Reputation: 4826
I'm trying to get my function to add 1 day to the date I send it ,but I can;t figure out how to match the MySQL formatting. I've currently got:
$result = mysql_query($query);
$lastdate = mysql_result($result, 0, 'date');
$date = strtotime(date("Y-m-d", strtotime($lastdate)) . " +1 day");
I know the $date =
line is incorrect somewhere, but I don't understand the function too well. It's being given the date in the format YYYY-mm-dd ($query is just getting the last date in the database), due to how MySQL stores dates.
I'm guessing that using the strtotime function isn't the right thing to do, or I've got the format/idea all wrong.
Thanks for any help, this is annoying me now :(
Upvotes: 2
Views: 22375
Reputation: 19552
I think you want $date = date("Y-m-d", strtotime("+1 day", $lastdate))
.
You may need to convert $lastdate
using strtotime
.
Upvotes: 5
Reputation: 2165
You could just add 86400 seconds to the result from strtotime(), since that returns an integer number of seconds since 1/1/1970, and there are 86400 seconds in a day.
$lastdate = '2011-10-11 22:07:11';
$date = date("Y-m-d", strtotime($lastdate) + 86400);
echo $date;
Outputs:
2011-10-12
Upvotes: 0