PDA

View Full Version : calculate date variables??


tai4hang
09-04-2002, 06:54 AM
Dear all,

i have a string variable "12-Sep-02",
if i want to add 7 days on it and become 19-Sep-02, are there any direct functions to convert a string to date variables and calculate the date???

Thx.

mordred
09-04-2002, 10:39 AM
There are no "real" date variables such as the Date object of JavaScript in PHP, date calculation is usually done with the help of UNIX timestamps.

However, there is function called strtotime() that converts a string of certain format to a timestamp. You can make use of this function to generate a timestamp and then do date arithmetic in mktime().


$ts = getdate(strtotime("12-Sep-02"));
$newTs = mktime(0, 0, 0, $ts["mon"], $ts["mday"] + 7, $ts["year"]);

echo date("d.m.Y", $newTs);