Jump to content

php date help


phporcaffeine

Recommended Posts

I need to be able to tell the next day, no matter what the current day is.  I am having trouble when it comes to the ends of the month.

<?php

$day = date("j") + 86400;

echo "Tomorrow is: " . date("m/") . $day . "/" . date("Y");

// this works fine until you encounter the 30th or 31st of a month, how do I account for that?

?>

-TIA
Link to comment
Share on other sites

[quote author=pedrobcabral link=topic=110474.msg446631#msg446631 date=1159967276]
My ignorance made me do a code like to cal_days_in_month.. see if it was december blablabla, just to achieve a thing as simple as that!
[/quote]

hehe... we've all been there, [b]believe[/b] me... that's why this board is here: to help learn new techniques ;)
Link to comment
Share on other sites

If you want to go one day more for the present then you ho that way.
Imagine now you want to go one day more, but not from the present day.

I'm trying somethings but I'm not suceding.. i've this one now: date('20-01-1986',strtotime("tomorrow"));
Do you know what's the problem here to have in the output: 21-01-1982?
Link to comment
Share on other sites

keep in mind the arguments that date requires. the first argument is your [b]format[/b] and the second is a [b]UNIX timestamp[/b]. so, strtotime gets that timestamp for you:
[code]
<?php
$date = "1986-01-20";
echo date('m/j/Y', strtotime("$date +1 day"));
?>
[/code]

read up on the [url=http://www.php.net/strtotime]strtotime()[/url] and [url=http://www.php.net/date]date()[/url] pages in the manual to get a better feel for what is and is not readable to them.
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.