Solved

Insert date time

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

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…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

728 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