Micro Focus QTP (UFT) Forums
Date Functions - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Date Functions (/Thread-Date-Functions)



Date Functions - Anna - 07-29-2008

I have any birth date. For example 04/07/1973 I would like to take the current date - any birth date and get the person's current age. Is there a function I can use? For example 07/29/2008 - 04/07/1973 = 35
Thanks,
Anna


RE: Date Functions - Raj - 07-29-2008

Check this , i hope it's usefull for u

Code:
strBirthDate="10/10/2000"
vmonth = dateDiff("m",strBirthDate, date())
vday= datediff("d", strBirthDate, date())
If month(Now()) > month(strBirthDate)  OR month(Now()) = month(strBirthDate) Then
     If day(strBirthDate) = day(Now()) OR Day(Now()) > day(strBirthDate)Then
          vyear = DateDiff("y", year(strBirthDate), year(Now()))
    else
        vyear = DateDiff("y", year(strBirthDate), year(Now())) - 1    
    end if
    
else
       vyear = DateDiff("y", year(strBirthDate), year(Now())) - 1
End If

msgbox "Year::"& vyear



RE: Date Functions - Anna - 07-29-2008

Hi,
This seems to work well. Thank you!