Reputation: 9
Having problems adding 1 month to a variable from a database trying numerous methods given on the forum:
$row["pchargedate"] returns 2018-03-01
$newduedate = date('Y-m-d', strtotime('+1 month', $row["pchargedate"])) ;
-returns 0000-00-00
$newduedate = date('Y-m-d', strtotime('+1 month', $row["pchargedate"])) ; }
$newduedate = date ( 'Y-m-d' , $newduedate );
- returns 1970-01-01
$duedate = DateTime::createFromFormat('Y-m-d', $row["pchargedate"]);
$duedate = $duedate->format('d-m-Y');
if ($row["pchargedate"] == '1' ) { $newduedate = strtotime ( '+1 month' , strtotime ( $pchargedate ) ) ; }
$newduedate = date ( 'Y-m-d' , $newduedate );
- $duedate returns 01-03-2018 but $newduedate is 1970-01-01
Any help much appreciated.
Upvotes: 0
Views: 90
Reputation: 2738
strtotime — Parse about any English textual datetime description into a Unix timestamp
The Syntex is
int strtotime ( string $time [, int $now = time() ] )
What about this
<?php
$row = "2018-03-01";
echo date('Y-m-d', strtotime($row. ' + 1 month'));
//Outputs 2018-04-01
And the syntex you are using is
$newduedate = date('Y-m-d', strtotime('+1 month', $row["pchargedate"])) ;
Which is wrong. so it will output by default date
Kindly read This Documentation.
Upvotes: 1