date conversion and calculation problem...
| From: | py | Date: | Tue, 13 Nov 2001 03:46:46 +0000 |
| Subject: | date conversion and calculation problem... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-74352@lists.php.net to get a copy of this message | ||
Hello,
I have 2 date string like this
$t1 = "2001-11-12 17:30:10";
$t2 = "2001-11-12 17:15:32";
I need to substracts the number of seconds from $t2 from $t1
(because after I have another script thats converts the number of seconds to
minutes, hours or days if necessary)
I tried: (but it does not give me something rigth)
$t1 = explode( " ", $t1 );
$t2 = explode( " ", $t2 );
// now $t1[0] contains date $t1[1] contains hours
$arr_date1 = explode( "-", $t1[0] );
$arr_date2 = explode( "-", $t2[0] );
$arr_time1 = explode( ":", $t1[1] );
$arr_time2 = explode( ":", $t2[1] );
// now $arr_time1[0] contains the hour, $arr_time1[1] contains minute,
$arr_time1[2] contains second
$t1 = mktime( $arr_time1[0], $arr_time1[1], $arr_time1[2], $arr_date1[1],
$arr_date1[1], $arr_date1[0] );
$t2 = mktime( $arr_time2[0], $arr_time2[1], $arr_time2[2], $arr_date2[1],
$arr_date2[2], $arr_date2[0] );
print "<br>$t2 - $t1 = ". ( $t2 - $t1);
hope you can help me,
py