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 |
newbietosql1221
Starting Member
25 Posts |
Posted - 2010-10-06 : 13:05:50
|
Can someone tell me how to get previous monthso far what i got current month day but i need previous month, tahnksmy_date >= dateadd(month, datediff(month, 0, getdate()), 0) I need previous month |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-10-06 : 13:09:49
|
dateadd(month, datediff(month, 0, getdate()) - 1, 0) |
 |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2010-10-06 : 13:45:05
|
[code]where -- Date GE start of last month my_date >= dateadd(month,datediff(month,0,getdate())-1,0) and -- Date before start of current month my_date < dateadd(month,datediff(month,0,getdate()),0)[/code]CODO ERGO SUM |
 |
|
newbietosql1221
Starting Member
25 Posts |
Posted - 2010-10-06 : 14:01:34
|
Thank all you guys are great keep up the good work. So for current year would it be my_date >= DATEADD(yy,0,'2010') ? |
 |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2010-10-06 : 15:35:44
|
quote: Originally posted by newbietosql1221 Thank all you guys are great keep up the good work. So for current year would it be my_date >= DATEADD(yy,0,'2010') ?
Only if the current year is 2010.CODO ERGO SUM |
 |
|
newbietosql1221
Starting Member
25 Posts |
Posted - 2010-10-07 : 09:22:50
|
Thanks all you guys are great everyone of you. |
 |
|
|
|
|
|
|