Calculate the time stamp of year
Given that I have $num_years
, how can I add it to Time()
to g开发者_如何学编程et a time stamp $num_years
hence?
strtotime("+$num_years years")
will give you a timestamp $num_years
years in the future.
try
echo strtotime("now + $num_years years");
Is this what you're after?
$num_years = 5;
$future = strtotime("+{$num_years} years");
echo strftime('%Y %a %d %m, %T', strtotime('+' . $num_years . ' years') );
Change strfttime
format according your needs.
Check out strtotime
man page http://php.net/manual/en/function.strtotime.php
Well if you looking for the timestamp for just that time then use mktime
mktime(0,0,0,0,0,$noOfYears);
http://www.php.net/manual/en/function.mktime.php
is this what you want ?
//Example to add 1 year to a date object
$num_years = 1;
$currentDate = date("Y-m-d");// current date
//Display the current date
echo "Current Date: ".$currentDate."<br>";
//Add one year to current date
$dateOneYearAdded = strtotime(date("Y-m-d", strtotime($currentDate)) . " +$num_years years");
echo "Date After adding one year: ".date('l dS \o\f F Y', $dateOneYearAdded)."<br>";
精彩评论