Jump to content

Date() math


AV1611

Recommended Posts

I had the same problem as this a while ago and I had to use strtotime to make it work, this is how I did it

[code]

$basedate = strtotime("21 june 2006");
$plusdate = strtotime("-1 day", $basedate);
$finaldate = date("Y-m-d ", $plusdate);
echo ($finaldate);
[/code]
produces
[code]
2006-06-20
[/code]

if you look at:-
[a href=\"http://uk.php.net/manual/en/function.date.php\" target=\"_blank\"]http://uk.php.net/manual/en/function.date.php[/a] - it will tell you all bout the different ways it can represent dates "Y-m-d " produces a date as in your origonal post 2006-06-21

[a href=\"http://uk.php.net/strtotime\" target=\"_blank\"]http://uk.php.net/strtotime[/a] lets you know what this does and how it does it

hope this helps
Link to comment
https://forums.phpfreaks.com/topic/12742-date-math/#findComment-48848
Share on other sites

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
[code]
$basedate = strtotime("21 june 2006");
$finaldate = date("Y-m-d ", strtotime("-1 day", $basedate));
[/code]
[/quote]

if you had done your method but with an extra set of parenthases ( spelt wrong but hey ho) it may have worked
you need the final variable in the date function to be completed before the date function finishes its call so if you would have done
[code]
$basedate = strtotime("21 june 2006");
$finaldate = date("Y-m-d ", (strtotime("-1 day", $basedate)));
[/code]

your method would work

and in fact I have just tested it and it does work that way
Link to comment
https://forums.phpfreaks.com/topic/12742-date-math/#findComment-48864
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.