Create Expiration date function from current date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Create Expiration date function from current date

Post by cap2cap10 »

:banghead: Greetings phpiers. I'm kind of a newbie programmer and I need help creating a function that will take the current date and add a # of days to create an expiration date that can be stored in MySQL. Are there any pro up to the task?

Thanks in advance,

Batoe
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Create Expiration date function from current date

Post by Christopher »

The way these date calculations are usually done is to convert the date to a Unix timestamp. That is an integer that represents seconds since 1/1/1970. Once you have that then you can add 60*60*24 times the number of days to get to a date in the future. Finally, there are functions to convert back from a timestamp to a text date. Check the manual for the date/time functions. There are examples in the entry and user supplied examples.
(#10850)
Post Reply