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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 [Resolved] Convert to Date Format yyyy-mm-dd

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2010-05-06 : 11:36:53
I'm doing this:

set @DateFrom1	= dateadd(month, datediff(month, 0, getdate()) - 13, 0) -- start date 
set @DateTo1 = DATEADD(MONTH, 1, @DateFrom1)
set @DateTo1 = DATEADD(Day, -1, @DateTo1)


It renders:

Apr 1 2009 12:00AM
Apr 30 2009 12:00AM

How can I set result to be in yyyy-mm-dd format? Thank you.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-05-06 : 11:41:00
you don't need to as long as your data type is datetime. Leave the formatting of the date to the front end application


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2010-05-06 : 11:41:56
I am connecting to an Advantage db where field is db timestamp, that is why
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-05-06 : 11:43:55
[code]select convert(varchar(10),@DateFrom1,120),convert(varchar(10),@DateTo1,120)[/code]
But its best to do the formatting in the Front End.
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2010-05-06 : 12:31:42
That will work. Thank you.
Go to Top of Page
   

- Advertisement -