tags:

views:

166

answers:

5

i want to have a date 6 years from now?

how do i do that?

+13  A: 
<?php
$timestamp = strtotime('+6 years');
echo date('Y-m-d H:i:s', $timestamp);
?>
hsz
Is that really how you do this in PHP?
ChaosPandion
Yes, what did you expect?
Pekka
I guess I am spoiled by the .NET DateTime object.
ChaosPandion
PHP offers a DateTime object as well, although its modification format matches strtotime's awesome voodoo. http://www.php.net/manual/en/datetime.modify.php
Alan Storm
Voodoo... that's a good way to put it.
ChaosPandion
+1  A: 
strtotime('+6 years');

you can pass that timestamp into something like strftime(); strtotime

Chuck Vose
+1  A: 

Still laughing about ChaosPandion's comment :)

echo strtotime ("+6 years");

should do the trick.

Pekka
A: 

189302400 is the number of seconds in 6 years.

Get the current timestamp, then add 189302400, and then convert the timestamp to a date string.

Crowe T. Robot
+1 for omitting the necessary code and focusing on the timestamps
Peter Lindqvist
Does that six-year period include 0, 1, or 2 leap years?(1700, 1800, 1900, 2100, 2200, etc, are not leap years.)
George V. Reilly
Good in theory, but broken in practice since it doesn't properly account for leap years. 1997-2003 needs to subtract a day since 2000 wasn't a leap year and 2003-2009 needs to add a day since both 2004 and 2008 were leap years. That even assumes you planned for at least one leap year within 6 years.
Jonathan Lonowski
2000 *was* a leap year: http://en.wikipedia.org/wiki/Leap_year#Gregorian_calendar
George V. Reilly
+1  A: 

Your description isn't very precise, but echo date("Y-m-d", strtotime("+6 years")); might be what you need ...

johannes