hello!

say you have 2 dates;
200809261800(start) to 200809261930(end) and you minused the start from the end date, how can you re-format the remaining time? in this case 130.

for some reason $totTimeD = date('G:i',strtotime($totTime));
just gives me 1:00 from the remaining time 130

$eve_start =$row['eve_start'];
		$eve_end =$row['eve_end'];

		$totTime = $eve_end-$eve_start;
		$totTimeD = date('G:i',strtotime($totTime));

		$eve_startD = date('d M y, G:i',strtotime($row['eve_start']));
		$eve_endD = date('d M y, G:i',strtotime($row['eve_end']));

		$option ="$eve_startD to $eve_endD ($totTime $totTimeD)";

is this the best way to figure out an events duration?

thanks in advance! D.

    How are the times stored in the database? As DATETIME columns?

      no, they're just varchar(12).

      D.

        function date_diff($d1, $d2){
            $d1 = (is_string($d1) ? strtotime($d1) : $d1);
            $d2 = (is_string($d2) ? strtotime($d2) : $d2);
        
        $diff_secs = abs($d1 - $d2);
        $base_year = min(date("Y", $d1), date("Y", $d2));
        
        $diff = mktime(0, 0, $diff_secs, 1, 1, $base_year);
        return array(
            "years" => date("Y", $diff) - $base_year,
            "months_total" => (date("Y", $diff) - $base_year) * 12 + date("n", $diff) - 1,
            "months" => date("n", $diff) - 1,
            "days_total" => floor($diff_secs / (3600 * 24)),
            "days" => date("j", $diff) - 1,
            "hours_total" => floor($diff_secs / 3600),
            "hours" => date("G", $diff),
            "minutes_total" => floor($diff_secs / 60),
            "minutes" => (int) date("i", $diff),
            "seconds_total" => $diff_secs,
            "seconds" => (int) date("s", $diff)
        );
        }
        
        
        $a = date_diff("200711012130", "200711012145");
        
        echo "<pre>";
        print_r($a);
        echo "</pre>";
        

        Array
        (
        [years] => 0
        [months_total] => 0
        [months] => 0
        [days_total] => 0
        [days] => 0
        [hours_total] => 0
        [hours] => 0
        [minutes_total] => 15
        [minutes] => 15
        [seconds_total] => 900
        [seconds] => 0
        )

        seems to work pretty well. though now i have to figure out how to use print_r !

          Write a Reply...