using dates 
Author Message
 using dates

Hi,  i need to subtract datea [which is a date in the future] from dateb
[which is todays date] and then convert the difference in the format of
years/months/days/hours/minutes.

does anyone have an example of how to do this ?

thanks
Barry



Tue, 08 May 2001 03:00:00 GMT  
 using dates
check function datediff
and format the result returned from dateDiff.

Rafat Sarosh
http://www.azan.net/sarosh

Quote:

>Hi,  i need to subtract datea [which is a date in the future] from dateb
>[which is todays date] and then convert the difference in the format of
>years/months/days/hours/minutes.

>does anyone have an example of how to do this ?

>thanks
>Barry



Tue, 08 May 2001 03:00:00 GMT  
 using dates
Rafat and Barry,

datediff is the right function to get the minutes - after that, you will
need to do some math to calculate the other values
(hours/days/months/years).

-Meade

Quote:

>check function datediff
>and format the result returned from dateDiff.

>Rafat Sarosh
>http://www.azan.net/sarosh


>>Hi,  i need to subtract datea [which is a date in the future] from dateb
>>[which is todays date] and then convert the difference in the format of
>>years/months/days/hours/minutes.

>>does anyone have an example of how to do this ?

>>thanks
>>Barry



Tue, 08 May 2001 03:00:00 GMT  
 using dates
This should help.

Public Function GetAgeString(StartDate As Variant, EndDate As Variant) As
String
    Dim Years As Integer
    Dim Months As Integer
    Dim Days As Integer
    Dim tDate As Date
    If Not (VarType(StartDate) = vbDate And VarType(EndDate) = vbDate) _
        Or StartDate > EndDate Then
        GetAgeString = ""
        Exit Function
    End If
    Years = AgeYears(StartDate, EndDate)
    Months = AgeMonths(StartDate, EndDate)
    tDate = DateSerial(Year(StartDate) + Years, Month(StartDate) + Months,
Day(StartDate))
    Days = DateDiff("d", tDate, EndDate)
    GetAgeString = Years & " yrs " & Months & " mths " & Days & " days"
End Function

Function AgeYears(StartDate As Variant, EndDate As Variant) As Integer
    Dim varYears As Variant
    If IsNull(StartDate) Or IsNull(EndDate) Then AgeYears = 0: Exit Function
    varYears = DateDiff("yyyy", StartDate, EndDate)
    If EndDate < DateSerial(Year(EndDate), Month(StartDate), Day(StartDate))
Then
        varYears = varYears - 1
    End If
    AgeYears = CInt(varYears)
End Function

Function AgeMonths(StartDate As Variant, EndDate As Variant) As Integer
    Dim tMonths As Double
    tMonths = DateDiff("m", StartDate, EndDate)
    If (DatePart("d", StartDate) > DatePart("d", EndDate)) Then
              tMonths = tMonths - 1
    End If
    If tMonths < 0 Then
        tMonths = tMonths + 1
    End If
    AgeMonths = CInt(tMonths Mod 12)
End Function

wjs



Thu, 10 May 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Create Date array using Date range

2. Runtime error using Date() in SQL query

3. problems using Date() function

4. Calculating Age using date selected by User

5. #Name using Date()

6. #Name using Date()

7. Using Dates in VBA code

8. help using dates and dateadd function

9. Problem: Using date and timepicker in acces97 form.

10. Find and Restrict using dates

11. Find / Restrict using date and time

12. Using Dates In Word

 

 
Powered by phpBB® Forum Software