Jump to content

Problem adding 30 days to date??


A JM

Recommended Posts

Using two strtotime() functions is doubly-slow. If the original date can be understood by strtotime(), just do it all at once -

 

$duedate = date('m/d/y',strtotime("{$row['inv_submitted']} +30 days"));

 

If your inv_submitted field is in fact a DATE data type, just use the mysql DATE_ADD() function or directly add an INTERVAL in your query. To get the value formatted as a 'm/d/y', just use the mysql DATE_FORMAT() function in your query.

Sure..

 

For starters both of these declarations return strings..

So the first one will return, for example, 12/3/2009, and the second will return just add 30 days to todays date..

and you are trying to add them together which would never work...

$duedate = date("m/d/Y", strtotime($row['inv_submitted']));
$duedate = $duedate + date("m/d/Y", strtotime("+30 day"));

 

Have a read of this http://php.net/manual/en/function.strtotime.php for a better understanding of the strtotime function..

 

ah, makes sense I missed the adding strings together part, duh.. thanks.  :)

 

 

Sure..

 

For starters both of these declarations return strings..

So the first one will return, for example, 12/3/2009, and the second will return just add 30 days to todays date..

and you are trying to add them together which would never work...

$duedate = date("m/d/Y", strtotime($row['inv_submitted']));
$duedate = $duedate + date("m/d/Y", strtotime("+30 day"));

 

Have a read of this http://php.net/manual/en/function.strtotime.php for a better understanding of the strtotime function..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.