Datediff

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

When I use datediff, the Year I get back is not correct .At msdn I found the problem.(From 31/12/2003 to 1/1/2004 I get 1Year butt this is not correct.
Where can I find a function that give's me the exact Year ( for 31/12/2003 to 1/1/2004 this is 0 Year

Thx

JoskeXP
 
JoskeXP said:
When I use datediff, the Year I get back is not correct .At msdn I
found the problem.(From 31/12/2003 to 1/1/2004 I get 1Year butt this
is not correct.) Where can I find a function that give's me the exact
Year ( for 31/12/2003 to 1/1/2004 this is 0 Year)

2004 - 2003 = 1

How long is one year? 365 or 366 days? How long is one month? 28, 29, 30 or
31 days?


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
JoskeXP said:
I need this because I have to now of he's at least 21 year's old.
When I do 1/1/2004 - 31/12/2003 I get 1 Year but it's only 1 day
difference. When he's 20 Year 11 Months and 25 day's I only need 20
Year and noy 21 Year


Public Function GetAge( _
ByVal BirthDate As Date, ByVal ReferenceDate As Date) As Integer

GetAge = ReferenceDate.Year - BirthDate.Year

If ReferenceDate.Month < BirthDate.Month _
OrElse (ReferenceDate.Month = BirthDate.Month _
AndAlso ReferenceDate.Day < BirthDate.Day) Then
GetAge -= 1
End If

End Function


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
* "=?Utf-8?B?Sm9za2VYUA==?= said:
I need this because I have to now of he's at least 21 year's old.
When I do 1/1/2004 - 31/12/2003 I get 1 Year but it's only 1 day difference.
When he's 20 Year 11 Months and 25 day's I only need 20 Year and noy 21 Year

By subtracting the dates, you get a 'TimeSpan'. Check the number of
days the timespan includes.
 
Back
Top