?
Solved

Insert date time

Posted on 2013-01-17
5
Medium Priority
?
293 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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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 70

Expert Comment

by:Scott Pletcher
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

807 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