PHP add or subtract days,months,years,time from date("...")

Adding Days


[code]$currdate = date(“Y-m-d”);
$add_day = strtotime(‘+<strong>N</strong> day’, strtotime($currdate ));
$add_day = date(‘Y-m-d’, $add_day);
[/code]
or simply use

[code]
$add_day = date("Y-m-d", strtotime("+N day", strtotime(date("Y-m-d") )));
[/code]
it will result $add_day by adding N days to current date


Adding Months


[code]
$currdate = date(“Y-m-d”);
$add_month = strtotime(‘+<strong>N</strong> month’, strtotime($currdate ));
$add_month = date(‘Y-m-d’, $add_month);
[/code]
it will result $add_day by adding N months to current date


Adding Years


[code]
$currdate = date(“Y-m-d”);
$add_year = strtotime(‘+<strong>N</strong> year’, strtotime($currdate ));
$add_year = date(‘Y-m-d’, $add_year);
[/code]
it will result $add_day by adding N years to current date

for subtracting just add -N month or -N year or -N day instead of using plus(+N day)

Note:here N is any integer Number like 0,1,2,3,4,.....

Comments

Popular posts from this blog

Simple Mail Sending Contact Form using PHP and Jquery

Codeigniter with Admin LTE

onclick anchor tag open url in bootstrap model