Results 1 to 9 of 9

Thread: php date for tomorrow

  1. #1

    php date for tomorrow

    hey guys!! i just wanna ask if how am i going to code the date for tomorrow using php?

    i have this sample:

    PHP Code:
     
     
    $date_today
    =date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("y")));
    $date_tomorrow= ??? 
    that is date today how about the date for tomorrow? thanks!!

  2. #2
    here are two functions you can use:

    date format = 'DD-MM-YYYY'
    ( you can rewrite it for other formats )

    Code:
    function get_next_day( $date )
    {
        $next_day = date("d-m-Y",mktime(0, 0, 0, substr( $date , 3, 2), substr( $date , 0, 2) + 1, substr( $date , 6, 4) ));
    	return $next_day;
    }
    
    function get_prev_day( $date )
    {
        $next_day = date("d-m-Y",mktime(0, 0, 0, substr( $date , 3, 2), substr( $date , 0, 2) - 1, substr( $date , 6, 4) ));
    	return $next_day;
    }

  3. #3
    14
    posts
    Registered User
    Timestamp for tommorow:

    PHP Code:
    $tommorow mktime(date("H"), date("i"), date("s"), date("m"), date("d")+1date("Y")); 
    You can then show this correct like:

    PHP Code:
    echo date("d-m-Y"$tommorow ); 
    Thought this might look more simple then the previous example

  4. #4
    a MUCH EASIER way would be
    PHP Code:
    echo date('Y-m-d'strtotime("tomorrow")); 
    no mktime() required

    strtotime() is an amazing php function... it's one of the more impressive ones. lots of php magickery goin on in that http://us.php.net/strtotime. also seems as not many people are very familiar w/ it.

    if you wanted to add a time to it all you'd have to do is do:
    PHP Code:
    echo date('Y-m-d H:i:s'strtotime("tomorrow 16:30:15")); 
    if you don't add a time it defaults to your server time

    PHP Code:
    // today
    $today date('Y-m-d'strtotime("today"));

    // tomorrow
    $tomorrow date('Y-m-d'strtotime("tomorrow"));

    // yesterday
    $yesterday date('Y-m-d'strtotime("yesterday")); 
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  5. #5
    1,839
    posts
    Registered User
    thats cool stuff right there

  6. #6
    14
    posts
    Registered User
    Quote Originally Posted by simplistik View Post
    a MUCH EASIER way would be
    strtotime() is an amazing php function... it's one of the more impressive ones. lots of php magickery goin on in that http://us.php.net/strtotime. also seems as not many people are very familiar w/ it.
    Impressive! Didn't know this at all! Thanks for sharing

  7. #7
    Quote Originally Posted by Cage View Post
    Impressive! Didn't know this at all! Thanks for sharing
    Yea I didn't know about it until about 2 months ago, has saved me quite a bit of time not having to screw w/ mktime()
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  8. #8
    I really enjoy the moments when you have things to say, Simp...

    (I hope that sounded just as hetero' as I wanted.)
    "Give me the place to stand, and I shall move the earth" - Archimedes
    "The whole problem with the world is that fools and fanatics are always so certain of themselves, but wiser people so full of doubts." - Bertrand Russell

  9. #9
    Quote Originally Posted by SlicDiggy View Post
    I really enjoy the moments when you have things to say, Simp...

    (I hope that sounded just as hetero' as I wanted.)
    I dunno how to take that
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012