Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

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 1 users browsing this thread. (0 members and 1 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