Solved

Insert date time

Posted on 2013-01-17
5
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 143

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
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…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

734 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