Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get a date 6 years from now?

Tags:

date

php

i want to have a date 6 years from now?

how do i do that?

like image 746
never_had_a_name Avatar asked Dec 06 '09 00:12

never_had_a_name


4 Answers

<?php
$timestamp = strtotime('+6 years');
echo date('Y-m-d H:i:s', $timestamp);
?>
like image 184
hsz Avatar answered Oct 19 '22 08:10

hsz


date_default_timezone_set('America/Los_Angeles'); //required if not set
$date = new DateTime('1/1/1981');
$date->modify('+60 year');
echo $date->format('Y-m-d');

Above is not affected by unix time stamp date range (before 1970 and after 2038).

Also you can directly compare dates with Comparison operators directly, no need convert them to Time stamp.

Requires PHP 5.3

like image 20
z2z Avatar answered Oct 19 '22 07:10

z2z


strtotime('+6 years');

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

like image 21
Chuck Vose Avatar answered Oct 19 '22 07:10

Chuck Vose


Still laughing about ChaosPandion's comment :)

echo strtotime ("+6 years"); 

should do the trick.

like image 31
Pekka Avatar answered Oct 19 '22 07:10

Pekka