Insert date time

I have a part of a sql script the does:

insert into tbl  (id,MydateTime)  values(1,'2012-08-24 16:41:00.000')

How can I change this to work on all sql servers.

(Ie it don't work on a german for example)
Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
my article describes how to do:

insert into tbl  (id,MydateTime)  values(1, convert(datetime, '2012-08-24 16:41:00.000',120)) 

Open in new window

Convert your date into datetime format

check the following for date conversion
Pratima PharandeCommented:
Monica PSoftware DeveloperCommented:
Try to use the below format is suitable for u


Get the Date and convert into above format and insert into Table (ie using storedProcedure)
Scott PletcherSenior DBACommented:
Format 'YYYYMMDD hh:mm[:ss[.sss]]' always works, regardless of any date and/or language settings.

insert into tbl  (id,MydateTime)  values(1,'20120824 16:41:00.000')

Using CONVERT code(s) instead just add chances for errors and forces everyone to (1) pre-memorize CONVERT codes or (2) look up CONVERT codes to be sure of the date.  So it just doesn't make any sense to do that.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.