Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to compute birthday?

Status
Not open for further replies.

hstijnen

Programmer
Nov 13, 2002
172
NL
Hi,

Does anyone know an elegant method to compute someones birthday from his date-of-birth (given in a TDateTime)?
I'm able to decode the year from a given TDateTime, but I don't see how to set the year.

thx Henk
 
Do you mean you want to get a TDate containing the date of the person's next
birthday?

You could use TDateTime::DecodeDate to break the date-of-birth down into year/month/day, get the current year also using DecodeDate, combine that with the person's month/day, then use TDateTime::EncodeDate to get a TDate. If that is less than the current date, add 1 to the year, and EncodeDate again.
 
Thanks, Tony!
It's a perfect solution. I didn't see EncodeDate under the methods of TDateTime, but now I have it.

Cheers,
Henk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top