Hi
Assuming I have a specific date in 3 variables:
$day (1-31)
$month (1-12)
and $year (1900-2100)
I would like to know what the date would be one day from now or what it was the day before.
Or what would be the date one month from now and one month before
Or what would be the date one year from now and one year before
Is there a way to get this information using Date/Time PHP functions without resulting to explicit calculations (if I am in February there are 28 days, except...)
For example, if the date is:
$day = 31
$month = 3
$year = 2005
Then one day from now it would be 1/4/2005
regards
how to get get the next/previous date
Moderator: General Moderators
The function you're looking for is strtotime(). Here's how I'd do it:
and so on with the +1 month, +1 year, etc
Code: Select all
$day = 02;
$month = 11;
$year = 2222;
$future_day = strtotime('+1 day',strtotime($year . $month . $day))
Last edited by pickle on Tue Mar 15, 2005 10:26 am, edited 1 time in total.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
This should sort you out...i dont think pickles example works....return -1 for me.
Code: Select all
$day = 02;
$month = 11;
$year = 1999;
echo date("d-m-Y", strtotime("+1 day", mktime(0, 0, 0, $month, $day, $year)));Your obviously right - mine doesn't work. The strtotime documentation says it can take GNU date input format. A valid pure number format description can be found here: http://www.gnu.org/software/tar/manual/ ... tml#SEC116
Did someone lie to me
or am I an idiot? In either case, ~Pimptastic's will work too.
Did someone lie to me
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.