PDA

Click to See Complete Forum and Search --> : [2.0] date formatting...


bnathvbdotnet
Jul 7th, 2006, 03:14 PM
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.

ComputerJy
Jul 7th, 2006, 05:11 PM
DateObject.ToString("dd-MMM-yyyy");

jmcilhinney
Jul 7th, 2006, 05:56 PM
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.