View Full Version : adding hours to older date
wassimk
06-09-03, 07:08 PM
hello,
i have a quick question, how can i take a date older then 1970 and turn it into a timestamp so i can increment it by 60*60 seconds. then convert it back into a easy to read date?
what i want is to take June 16, 1815 8a.m. and increment it by 1 hour each time the script is called.
thanks,
wassim
wassimk
06-16-03, 11:49 PM
I guess this isn't possible, in any case, I put all dates in a database and just referenced the date by the turn number.
Check http://gremlins.mirrors.phpclasses.org/browse.html/class/9.html
May be one of the classes offer functionality you want.
Regards,
JD
I checked upon,
I think trying out this class will be a good idea!
http://gremlins.mirrors.phpclasses.org/browse.html/package/943.html
Regards,
JD
wassimk
06-17-03, 02:06 AM
THANKS phpkid, I'm going to give it a try!
mktime seems to be your closes bet for a php function however you will need to convert your month to an intiger which is simple enought heres something i just wrote and it seems to work but on windows systems it will not work with the date you gave me but thats to be expected lol.
<?php
/* the date string*/
$s_time = 'June 16, 1999 8am';
/* array of months */
$months = array (
"January" => "1",
"February" => "2",
"March" => "3",
"April" => "4",
"May" => "5",
"June" => "6",
"July" => "7",
"August" => "8",
"September" => "9",
"October" => "10",
"November" => "11",
"December" => "12"
);
/* some time conversion, not the best but it will do */
$s_time = str_replace(',','',"$s_time");
$s_time = str_replace('am','',"$s_time");
$s_time = str_replace('pm','',"$s_time");
$s_time = explode(' ',$s_time);
/* make the time */
$maketime = mktime ($s_time[3], 0, 0, $months[$s_time[0]], $s_time[1], $s_time[2]);
/* time stamp */
echo "$maketime<br>";
/* check if we did it right, heres it converted back */
echo date("M-d-Y", $maketime);
?>
vBulletin® v3.6.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.