Results 1 to 3 of 3

Thread: [2.0] date formatting...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    [2.0] date formatting...

    DateTime dt = DateTime.Now;
    string dt1 = dt.ToShortDateString();

    so far my sql statement is at this stage

    "SELECT * FROM CMCHOLIDAYS WHERE COUNTRY = 'US' AND HOLIDAYDATE = '07/07/2006'"

    I need to convert 07/07/06 which is dt1 variable to '07-Jul-2006' format.

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [2.0] date formatting...

    Code:
    DateObject.ToString("dd-MMM-yyyy");
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] date formatting...

    The real question is why are you storing dates in a database as text when you should be storing them as date objects? Then you would use a date literal, e.g. #7/07/2006#, or a parameter of appropriate type. Dates should be maintained as date objects wherever possible and only converted to strings when you need to display them. That way you can always perform comparisons or arithmetic on the date objects with ease and there is no issue with conversion or format because date objects have no format. It's only when converting to or from strings that format becomes an issue so if you avoid that the issue never arises.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width