I've got problem to adding timestamp with integer , I have start_date (timestamp) and month_pay . I want to add month of start_date with month.
eg
start_date = 2015-02-04 12:38:58 , month_pay = 1
=> total = 2015-03-04
list($year, $month, $day) = array_values(date_parse($timestamp));
$total_month = $month_pay + $month ;
echo $total_month
In this way , I just show Year & Month & Day , but this is not I want.
Maybe this is what you want?
$date = date_create('2015-02-04 12:38:58');
date_add($date, date_interval_create_from_date_string('30 days'));
// 1 month is not quite good duration / time interval
echo date_format($date, 'Y-m-d H:i:s');
The output would be: 2015-03-06 12:38:58
Change it to 28 days
(for this year, or 1 month
as suggested by @ fortune ) if you want it to be 4th March.
Assuming $timestamp is a string representing a date, and $month_pay are number of months you want to add to this date:
$month_pay = 1;
$totalDate = strtotime($timestamp) + ($month_pay*86400);
now $totalDate is the timestamp of the final date.
echo date("Y-m-d", $totalDate);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.