Wednesday, January 28, 2009

problem inserting a date into a SQL server

You should format the date using the ISO unseparated date format, which is YYYYMMDD. Do not use any separator for the year, month, or day. Like this....

Insert Into SomeTable(DateColumn) Values('20090128')
Update SomeTable Set DateColumn = '20090128' Where Id = 1

If you have a time included with your date, then the format should be: YYYYMMDD hh:mm:ss
Ex: '20090128 5:05 PM'
If you use this format, you will never have a problem.

1 comment:

  1. System.DateTime.Now.ToString("yyyyMMdd"))

    Dim myDate As DateTime = DateTime.Now
    myDate = Convert.ToDateTime("12/10/2007")