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



 
Previous Posts
    - 9 Tips for creating indexes in SQL Server
    - Performance Tip 1: Avoid non-sargable WHERE-clause...
    - 23 Tips to improve the performance of your SQL que...
    - A factsheet for SQL Server developers
    - How to replace certain word with a hyperlink using...
    - How to Highlight a specific word in HTML content (...
    - how to extract SRC from IMG elements in HTML code
    - How to extract URL and Anchor from HTML content
    - Grab the content of a (GZIP) webpage using C#
    - How to extract the host name from an URL (C#)

Archives
    - April 2007
    - May 2007
    - April 2008


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