Solved

Insert date time

Posted on 2013-01-17
5
284 Views
Last Modified: 2013-01-20
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)
0
Comment
Question by:pucko73
5 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 38786868
my article describes how to do:
http://www.experts-exchange.com/Database/Miscellaneous/A_1499-DATE-and-TIME-don%27t-be-scared-and-do-it-right-the-first-time.html

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

Open in new window

0
 
LVL 5

Expert Comment

by:RehanYousaf
ID: 38786878
Convert your date into datetime format

check the following for date conversion

http://www.sql-server-helper.com/tips/date-formats.aspx
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38786897
0
 
LVL 10

Expert Comment

by:Monica P
ID: 38786981
Try to use the below format is suitable for u

 SELECT CONVERT(VARCHAR(19), GETDATE(), 120)

Get the Date and convert into above format and insert into Table (ie using storedProcedure)
0
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 38787773
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.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need Counts 11 40
Using MS SQL / SQLLite for iPhone  App 7 26
Report Builder 9 25
Access Migration to Sql Server 2 18
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now