Solved

Insert date time

Posted on 2013-01-17
5
287 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: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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL LINE CONTINUATION ISSUE 12 33
Help Required 2 31
How to search for strings inside db views 4 27
SQL Error - Query 6 25
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

776 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