PDA

View Full Version : Adding a year to a timestamp.


Dave
07-20-03, 04:12 PM
How can I add exactly one year to a timestamp? For example, if I have July 23, 2003 as a timestamp, how can I make it July 23, 2004?

Robert
07-20-03, 04:26 PM
Originally posted by Dave:

How can I add exactly one year to a timestamp? For example, if I have July 23, 2003 as a timestamp, how can I make it July 23, 2004?

simple script i found

<?
// get the current timestamp into an array
$timestamp = time();
echo strftime( "%Hh%M %A %d %b",$timestamp);
echo "<p>";
$date_time_array = getdate($timestamp);

$hours = $date_time_array["hours"];
$minutes = $date_time_array["minutes"];
$seconds = $date_time_array["seconds"];
$month = $date_time_array["mon"];
$day = $date_time_array["mday"];
$year = $date_time_array["year"];

// use mktime to recreate the unix timestamp
// adding 19 hours to $hours
$timestamp = mktime($hours + 19, $minutes,$seconds ,$month, $day,$year);
echo strftime( "%Hh%M %A %d %b",$timestamp);
echo "<br>~E after adding 19 hours";
?>

Modify it to your needs