On Fri, 03 Aug 2007 21:39:11 +0200, rhaazy <rh****@gmail.comwrote:
I need to know how I can format a string in C# to get the current date/
time, so that I can do a comparison against a date time column in MS
SQL Server 2005.
The date/time column in the database is of the followin format:
mm/dd/yyyy hh:mm:ss AM/PM
thanks in advance.
Well, to get the text representation of a date in that format, you could simply do DateTime.Now.ToString(), possibly with formatting like DateTime.Now.ToString("MM\\/dd\\/yyyy hh\\:mm\\:ss tt"). Couldn't get the AM/PM on my system to work, without also changing the CultureInfo to something using 12 hour clocks.
Anyhow, why do you need to do this? If the comparison is done on the sql server, simply pass a datetime (provided the datetime is stored as a datetime). If the comparison is done in code, simply compare two datetimes. Use SqlParameter to pass the DateTime structure.
--
Happy coding!
Morten Wennevik [C# MVP]