|
-
Jul 7th, 2006, 03:14 PM
#1
Thread Starter
Hyperactive Member
[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.
-
Jul 7th, 2006, 05:11 PM
#2
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
-
Jul 7th, 2006, 05:56 PM
#3
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|