Jump to content

Archived

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

phporcaffeine

php date help

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

Share this post


Link to post
Share on other sites
http://us3.php.net/date

If you look at example 3 it shows you how to do something similar using mktime and date together.

Sorry i can't be of more help than that.

Share this post


Link to post
Share on other sites
It depends on your timezone, or use gm... to get the GMT!

[code]<?

echo 'Tomorrow is: ' . date ( 'm/d/Y', mktime ( 0, 0, 0, date ( 'n' ), ( date ( 'j' ) + 1 ), date ( 'Y' ) ) );

?>[/code]


me!

Share this post


Link to post
Share on other sites
why not just do:
[code]
<?php
echo "Tomorrow is: " . date('m/j/Y', strtotime("tomorrow"));
?>
[/code]

Share this post


Link to post
Share on other sites
Jesus! 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!

:o

Share this post


Link to post
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 ;)

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.