Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Change Format Datetime in sql server 2005

Author  Topic 

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2009-10-22 : 12:53:24
Hallo,

I am working with SQL server 2005, I have a datetime format set to for example 2006.12.31 00:00:00. I would like to change the SQL server datetime to the following format;

31/12/06 00:00:00 i.e., dd/mm/yy hh:mm:ss

What code can I run to set the date time as requested..

Thank you very much.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-10-22 : 12:56:10
SELECT CONVERT(datetime,datefield,131)
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-10-22 : 13:53:03
quote:
Originally posted by dr223

I have a datetime format set to for example 2006.12.31 00:00:00. I would like to change the SQL server datetime to the following format: 31/12/06 00:00:00 i.e., dd/mm/yy hh:mm:ss

Does that mean that:
1. You want to convert a datetime to a string in the format dd/mm/yy?
2. You want to set the default date format of SQL to dd/mm/yy or that
3. You want to convert a string in format yyyy.mm.dd to a datetime?
4. Other?

Just as a guess:
SELECT CONVERT(VARCHAR(20), CONVERT(DATETIME, '2006.12.31 00:00:00', 101) ,131)
-- or
SELECT CONVERT(DATETIME, '2006.12.31 00:00:00', 101)
Go to Top of Page
   

- Advertisement -