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 |
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2014-05-06 : 03:29:03
|
I would like to get previous first and last month yyyy-mm-ddI tried this :select CONVERT(varchar,dateadd(hour,8,dateadd(d,-(day(dateadd(m,-1,getdate()-2))),dateadd(m,-1,getdate()-1))),121)select CONVERT(varchar,DATEADD(hour,8,dateadd(d,-(day(getdate())),getdate())),121)but i get the date as same as now. I have an issue on those with 1st april with earlier time will not be included.How can i get: start previous monthlast previous month |
|
VeeranjaneyuluAnnapureddy
Posting Yak Master
169 Posts |
Posted - 2014-05-06 : 04:11:42
|
select CONVERT(Date,dateadd(hour,8,dateadd(d,-(day(dateadd(m,-1,getdate()-2))),dateadd(m,-1,getdate()-1))),121)select CONVERT(Date,DATEADD(hour,8,dateadd(d,-(day(getdate())),getdate())),121)Veera |
 |
|
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2014-05-06 : 05:18:15
|
i will get this:2014-04-30 17:16:57.123any transaction after the time 17:16:57.123 will not be included..this is the issue im facing.. |
 |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2014-05-06 : 09:33:28
|
quote: How can i get: start previous monthlast previous month
I didn't quite get what you meant; I am guessing that you want the first day and last day of last month. If soSELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE())-1,0), DATEADD(mm,DATEDIFF(mm,0,GETDATE()),-1) You can use convert function to convert to appropriate format if needed. Use VARCHAR with a length e.g. VARCHAR(10). |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|