Date question

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
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Date question

Post by spacebiscuit »

Hi,

I have pulled a date from a database in the format:

YYY-MM-DD

If I want to add a day to this date can it be done in PHP?

Thanks.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Date question

Post by Celauran »

Check out strtotime()
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Re: Date question

Post by spacebiscuit »

Thankls I can't see how that will work though as it seems to work with unix time stamps?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Date question

Post by Celauran »

Code: Select all

$date = "2011-11-01";
$unix_time = strtotime($date);
$tomorrow = strtotime("+1 day", $unix_time);
echo date("Y-m-d", $tomorrow);
Better still, select the date as UNIX_TIMESTAMP from your database and save yourself some steps.
Post Reply