Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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:00AMApr 30 2009 12:00AMHow 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 applicationKH[spoiler]Time is always against us[/spoiler]
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
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.