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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 First and last date of Bi-Month

Author  Topic 

konark
Yak Posting Veteran

60 Posts

Posted - 2009-06-24 : 19:55:33
Find the first and last day of previous bi-month

assume today is 20090710 - July 10th 2009.

First date of last bimonth = 20090501 (may 1st)
Last date of last bimonth = 20090630 (may 30st)

Chandragupta Mourya

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2009-06-24 : 20:07:43
[code]
select
StartDate = dateadd(mm,datediff(mm,0,a.DT)-2,0),
EndDate = dateadd(mm,datediff(mm,-1,a.DT)-1,-1)
from
( --Test Data
select DT = convert(datetime,'20090710')
) a



Results:
StartDate EndDate
----------------------- -----------------------
2009-05-01 00:00:00.000 2009-06-30 00:00:00.000

(1 row(s) affected)

[/code]

CODO ERGO SUM
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-06-25 : 04:42:42
quote:
Originally posted by konark

Find the first and last day of previous bi-month

assume today is 20090710 - July 10th 2009.

First date of last bimonth = 20090501 (may 1st)
Last date of last bimonth = 20090630 (may 30st)

Chandragupta Mourya



Do you need 30th June or 31st May?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

konark
Yak Posting Veteran

60 Posts

Posted - 2009-06-25 : 13:03:50
quote:
Originally posted by madhivanan

quote:
Originally posted by konark

Find the first and last day of previous bi-month

assume today is 20090710 - July 10th 2009.

First date of last bimonth = 20090501 (may 1st)
Last date of last bimonth = 20090630 (may 30st)

Chandragupta Mourya



Do you need 30th June or 31st May?

Madhivanan

Failing to plan is Planning to fail




I am so sorry . you are correct .the last date should be June 30.

Chandragupta Mourya
Go to Top of Page
   

- Advertisement -