Adding and subtracting days, months, and years in current date using php

Adding Days

$current_date = date(“Y-m-d”);
$add_day = strtotime(‘+10 day’, strtotime($cdate));
$add_day = date(‘Y-m-d’, $add_day);

Subtracting Days

$current_date = date(“Y-m-d”);
$sub_day = strtotime(‘-10 day’, strtotime($cdate));
$sub_day = date(‘Y-m-d’, $sub_day);

Adding Months

$current_date = date(“Y-m-d”);
$add_month = strtotime(‘+3 month’, strtotime($cdate));
$add_month = date(‘Y-m-d’, $add_month);

Subtracting Months

$current_date = date(“Y-m-d”);
$sub_month = strtotime(‘-3 month’, strtotime($cdate));
$sub_month = date(‘Y-m-d’, $add_month);

Adding Years

$current_date = date(“Y-m-d”);
$add_year = strtotime(‘+1 year’, strtotime($cdate));
$add_year = date(‘Y-m-d’, $add_year);

Subtracting Years

$current_date = date(“Y-m-d”);
$sub_year = strtotime(‘-1 year’, strtotime($cdate));
$sub_year = date(‘Y-m-d’, $sub_year);

 

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