Tricky date function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jbaranski
    New Member
    • Nov 2007
    • 16

    Tricky date function

    I've working on conversion data related to our benefits. Our benefits eligibility date is as such, the first of the month 30 days after your hire date.

    ex. Hire Date = 11/5/2008. the 30 grace period ends on 12/5/2008 and the first of the following month, 1/1/2009 (the value i need returned), is when benefits go into effect.

    short of VB or stored processes, can pure SQL handle this??
  • jbaranski
    New Member
    • Nov 2007
    • 16

    #2
    I managed to figure it out. I'm so nice, in fact, that I added a CASE statement just in case their 30 day grace period ends on the first of the month.

    CASE
    WHEN DAY(DATEADD(d, 30, date)) = '1' THEN DATEADD(d, 30, date)
    ELSE DATEADD(dd,-(DAY(DATEADD(mm ,1,DATEADD(d, 30, date)))-1),DATEADD(mm,1 ,DATEADD(d, 30,date)))
    END AS SPECIAL_DATE

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Don't forget February and leap year.

      -- CK

      Comment

      Working...