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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.