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.
| Author |
Topic |
|
larus
Starting Member
17 Posts |
Posted - 2009-02-20 : 07:44:21
|
| Hello,How to get a date which was the first day of a month a year ago?Eg. this query produces 2008-02-20 00:00:00.000, and I want 2008-02-01 00:00:00.000select CAST(FLOOR(CAST(GetDate() AS FLOAT))AS DATETIME) - 366What would be the best solution? |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-02-20 : 07:46:51
|
| select dateadd(month,1,dateadd(year,datediff(year,0,getdate())-1,0))MadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-02-20 : 07:47:38
|
| orselect dateadd(year,-1,dateadd(month,datediff(month,0,getdate()),0))MadhivananFailing to plan is Planning to fail |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-02-20 : 08:10:51
|
| Also try thisSELECT DATEADD(D,-DAY(dateadd(yy,-1,GETDATE())-1),dateadd(yy,-1,GETDATE())) |
 |
|
|
larus
Starting Member
17 Posts |
Posted - 2009-02-20 : 08:27:23
|
| Thanks! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-20 : 09:38:36
|
| [code]select dateadd(mm,datediff(mm,0,dateadd(yy,-1,getdate())),0)[/code] |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-02-20 : 23:39:34
|
quote: Originally posted by larus Thanks!
Welcome |
 |
|
|
|
|
|
|
|