Monday, March 01, 2004

The datediff function

If you had been a programmer (anytime in life) you would have tried to find the diff between two dates you know what i say !! . There is a function called datediff in VB, SQL, and in VB.NET also in VBA (office products for novices)!! .

This function when it is compared between two dates and asks to check for the year diff its rather funny (in sense, it sticks to its literal sense).

eg:
datediff("yyyy",1/1/2002,1/1/2004) would give you an answer of 2 (yeah no marks for correct guesses)
datediff("yyyy",4/30/2002,1/1/2004) would also give an answer of 2 (can grant a mark if you had guessed it right)
datediff("yyyy",12/31/2002,1/1/2003) (one day diff) will give an answer of 1

So that means its rather simple logic

first the datediff checks whether the date is valid or not . if valid then takes the year and subrats the other one and provides the diff

its like 2003-2002 = 1 so the no of years between these two dates is 1

provided the dates inputed are valid .....


0 Comments:

Post a Comment

<< Home