| Author |
Topic  |
|
|
ms.gangadhar
Starting Member
India
8 Posts |
Posted - 06/05/2012 : 03:05:17
|
Hi,
I order to run a report for a particular month i need to fidn the first and last day of the month.How can we do this.
Regards, Gangadhara |
|
|
webfred
Flowing Fount of Yak Knowledge
Germany
8513 Posts |
Posted - 06/05/2012 : 03:13:14
|
-- ----------------------------------------- -- get 1. day of actual month -- ----------------------------------------- Select DateAdd(Month,DateDiff(Month,0,getdate()),0)
-- ---------------------------------------------- -- get LAST day of actual month -- ---------------------------------------------- Select DateAdd(dd,-1,DateAdd(Month,DateDiff(Month,0,getdate())+1,0))
No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
madhivanan
Premature Yak Congratulator
India
22460 Posts |
|
|
jeffw8713
Aged Yak Warrior
USA
693 Posts |
Posted - 06/05/2012 : 14:13:04
|
quote: Originally posted by webfred
-- ----------------------------------------- -- get 1. day of actual month -- ----------------------------------------- Select DateAdd(Month,DateDiff(Month,0,getdate()),0)
-- ---------------------------------------------- -- get LAST day of actual month -- ---------------------------------------------- Select DateAdd(dd,-1,DateAdd(Month,DateDiff(Month,0,getdate())+1,0))
No, you're never too old to Yak'n'Roll if you're too young to die.
For last day of the month, it is simpler to use:
DATEADD(month, DATEDIFF(month, -1, getdate()), -1)
Or, to move forward/backward xx number of months:
DATEADD(month, DATEDIFF(month, -1, getdate()) + xx, -1); -- where xx is the number of months forward/backward |
 |
|
| |
Topic  |
|
|
|