Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Increase date question 1

Status
Not open for further replies.

Lochness30

Programmer
Jun 9, 2004
23
CA
I have a date field in a mysql table. Say dUpdated(date)

I want to increase the date by 120 days and keep it in a date format.

I tried
Code:
$dUpdated = mktime(0, 0, 0, date("m")  , date("d")+120, date("Y"));
but that returned an integer. How can I increase in and keep it in a date format? Any help would be appreciated. Thanks!
 
What do you mean by "date format"? A string? Most data functions return an integer, as there is no special date data type. You can actually add seconds to the date.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
in mysql
Code:
update tablename set dUpdated = date_add(dUpdated, interval 120 day);

in php
Code:
function adddays($date, $numDays, $format = "Y-m-d"){
  if (!is_numeric ($date)) $date = strtotime($date);
  return date($format, strtotime("+ $numDays days", $date));
}
 
Thanks so much jpadie! Both the sql and php functions worked the way I was looking for.

I created a php function that would work more like the sql date_add function, where you could increment days, months, or years.

Thanks again for the prompt response!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top