Home | Index | Dotnet4all forum | Dotnet4all Snippets | Submit resources 
About | Mail us 
How to convert DateTime to SQL valid string (16 April 2007)


Using DateTime-fields in an SQL string is not difficult. Therefore the DateTime format must be 'YYYY-MM-DD HH:mm'.
For Example:
  "Select * from MyTable Where MyDateTimeField > '2007-01-01 12:00'"

For converting a .NET DateTime object to a valid SQL-compliant string using C# the following code snippet can be used:
  public static string ConverteerDatum(DateTime in_Datum)
{
return = in_Datum.Year + "-" + in_Datum.Month + "-" + _
in_Datum.Day + " " + in_Datum.ToLongTimeString();
}

Labels: , ,


Posted by Xander Zelders
 


0 Comments:

Post a Comment

<< Home

 
Previous Posts



Disclaimer & Terms of Use | DotNet4All.Com concept & © 2004 - 2007 by Zelders² - Holland