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 DateTime Format

Author  Topic 

joelseverich
Starting Member

34 Posts

Posted - 2009-02-16 : 14:12:23
Hi
Is there a way to change the datetime format
Ex. Change 01/01/2008 12:00:00 AM to 01/01/2008 only

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-16 : 14:18:41
[code]Convert(Varchar(10),datecol)[/code]
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-02-16 : 23:13:09
sodeep's Qeury was correct,but small Modification from above Query

select convert(varchar(12),' 01/01/2008 12:00:00 AM')
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-16 : 23:39:21
quote:
Originally posted by Nageswar9

sodeep's Qeury was correct,but small Modification from above Query

select convert(varchar(12),' 01/01/2008 12:00:00 AM')



So was that modification? I replaced hard-coded value with column name.
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-02-17 : 01:05:27
No, i changed the length of the varchar(10) to varchar(12)

For this: select convert(varchar(10),' 01/01/2008 12:00:00 AM')

output:- 01/01/200
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-02-17 : 01:29:31
quote:
Originally posted by joelseverich

Hi
Is there a way to change the datetime format
Ex. Change 01/01/2008 12:00:00 AM to 01/01/2008 only


Front end application has lot of formats

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ke.neelima
Starting Member

6 Posts

Posted - 2009-02-17 : 06:28:06
DECLARE @date VARCHAR(25)
SET @date = '2007-02-17 00:00:00.000'

SELECT CAST(CONVERT(VARCHAR(10),@date,112) AS DATETIME)
-- If looking only for DATE part
SELECT COALESCE(convert(char(10), @date, 112), '1900-01-01')

Regards

Neelima
Go to Top of Page

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2009-02-17 : 06:33:21
use this

DECLARE @date datetime
SET @date = getdate()
SELECT CONVERT(VARCHAR(10),@date,101)

But its always Preferred to change the format of date fields in front end application.

Karthik
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-17 : 09:09:56
quote:
Originally posted by joelseverich

Hi
Is there a way to change the datetime format
Ex. Change 01/01/2008 12:00:00 AM to 01/01/2008 only


Go with Madhi's suggestion. try to this at your front end application. which is your front end app?
Go to Top of Page
   

- Advertisement -