#php #dates

how to add a year to a php date

PHP ALL

$oneyear = strtotime("+1 year");

PHP 5.2

$date = getdate();
$oneyear = mktime(
        $date['hours'],$date['minutes'],$date['seconds'],
        $date['mon'],$date['mday'],$date['year']+1
    );
echo $oneyear;
echo PHP_EOL;

PHP 5.3

$oneyear = date_timestamp_get(
    date_add(date_create(),
        date_interval_create_from_date_string('1 year')));
echo $oneyear;
echo PHP_EOL;
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s