How to arrive remaining Months and Date of Current Year in Query?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ramli
    New Member
    • Dec 2010
    • 1

    How to arrive remaining Months and Date of Current Year in Query?

    Hello,

    I like to use a function like DateDiff to know Number of Years, Months, and Days between Days. As an Example, 5 Years, 10Months, 28Days for date between (JoiningDate)02 Jan05,(LastDate )30Nov10.

    The Number of Years is working fine in my Query using DateDiff. But I could not get 10 Months and 28 Days. Help me please.

    Ramli
  • atul gavali
    New Member
    • Oct 2010
    • 5

    #2
    i am giving you function to retrive day,month,year from
    date i hope it will help you

    Syntax : datediff(datepa rt,1st date,2nd date)
    Code:
             declare @day varchar(10)
             declare @month varchar(10)
             declare @year varchar(10)
           select @day   = datediff(day,1st date,2nd date) 
           select @month = datediff(month,1st date,2nd date)            
           select @year  = datediff(year,1st date,2nd date)

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      We don't simply code for you, in the absence of any attempt to work on a solution for yourself. What I can tell you is that your procedure will need to determine how many complete years are involved, before taking that many years away then determining how many complete months are involved. The same logic is then applied to the remainder for the days before you have a reliable result. There is no function available already to do this for you.

      Comment

      Working...