Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date and Time format in SQL Query 1

Status
Not open for further replies.

MasterPO

Programmer
Oct 10, 2002
51
0
0
US
I am trying to insert records into an existing table that has a specific format for dates and times in the existing records:
Date format (Last_Chg_Dt) is '2005-09-16 00:00:00.0000'
Time format (Last_Chg_Time) is '1900-01-01 12:26:16.060'

Using GetDate(), I cannot find a format to replicate these. They return either a date or a time or both, but not in the format as shown above!

Any ideas?
 
There should be an easier way to doing this but try this:
Code:
select convert(datetime, convert(varchar, getdate(), 101)), 
       convert(datetime, convert(varchar, getdate(), 114))

Regards,
AA
 
Thanks - I don't know how I missed these format numbers!
 
Is there a good place to get the definition for the format numbers?
 
You should be able to find it at Books Online (BOL).

Also googling on convert function sql server should take you to msdn link.

Regards,
AA
 
Look up CONVERT in the BOL.

-SQLBill

Posting advice: FAQ481-4875
 
BTW-there are a couple of FAQs on Dates and Times in this forum's FAQ area. Check them out.

-SQLBill

Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top