Jump to content


Photo

php date help


  • Please log in to reply
7 replies to this topic

#1 phporcaffeine

phporcaffeine
  • Members
  • PipPipPip
  • Advanced Member
  • 361 posts
  • LocationOhio, USA

Posted 04 October 2006 - 12:39 PM

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
Thanks,

Ryan Huff
President & Founder, MyCodeTree
support@mycodetree.com | http://mycodetree.com

#2 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 04 October 2006 - 12:50 PM

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.

#3 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 04 October 2006 - 12:51 PM

It depends on your timezone, or use gm... to get the GMT!

<?

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

?>


me!

#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 04 October 2006 - 01:00 PM

why not just do:
<?php
echo "Tomorrow is: " . date('m/j/Y', strtotime("tomorrow"));
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#5 pedrobcabral

pedrobcabral
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 04 October 2006 - 01:07 PM

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

#6 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 04 October 2006 - 01:15 PM

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!


hehe... we've all been there, believe me... that's why this board is here: to help learn new techniques ;)
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#7 pedrobcabral

pedrobcabral
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 04 October 2006 - 01:45 PM

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?

#8 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 04 October 2006 - 02:12 PM

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

read up on the strtotime() and date() pages in the manual to get a better feel for what is and is not readable to them.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users