View Full Version : php date for tomorrow
ivlem
December 20th, 2007, 02:04 AM
hey guys!! i just wanna ask if how am i going to code the date for tomorrow using php?
i have this sample:
$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!!
borrob
December 20th, 2007, 04:59 AM
here are two functions you can use:
date format = 'DD-MM-YYYY'
( you can rewrite it for other formats )
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;
}
Cage
December 20th, 2007, 06:47 AM
Timestamp for tommorow:
$tommorow = mktime(date("H"), date("i"), date("s"), date("m"), date("d")+1, date("Y"));You can then show this correct like:
echo date("d-m-Y", $tommorow );Thought this might look more simple then the previous example :pleased:
simplistik
December 20th, 2007, 10:14 AM
a MUCH EASIER way would be
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:
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
// today
$today = date('Y-m-d', strtotime("today"));
// tomorrow
$tomorrow = date('Y-m-d', strtotime("tomorrow"));
// yesterday
$yesterday = date('Y-m-d', strtotime("yesterday"));
joran420
December 20th, 2007, 07:06 PM
thats cool stuff right there :)
Cage
December 21st, 2007, 04:08 AM
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 :beam:
simplistik
December 21st, 2007, 08:21 AM
Impressive! Didn't know this at all! Thanks for sharing :beam:
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()
lorren.biffin
December 21st, 2007, 01:03 PM
I really enjoy the moments when you have things to say, Simp... :D
I hope that sounded just as hetero' as I wanted.
simplistik
December 21st, 2007, 01:43 PM
I really enjoy the moments when you have things to say, Simp... :D
I hope that sounded just as hetero' as I wanted.
:lol: I dunno how to take that :P :crazy:
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.