php - cant insert the difference of this into table -
this insert section $total_minutes , $total_hour cant inserted in table
$year = $_post['year']; $month = $_post['month']; $day = $_post['day']; $hour = $_post['hour']; $min = $_post['min']; $sec = $_post['sec']; $year1 = $_post['year1']; $month1 = $_post['month1']; $day1 = $_post['day1']; $hour1 = $_post['hour1']; $min1 = $_post['min1']; $sec1 = $_post['sec1']; $time_in = $year.'-'.$month.'-'.$day.' '.$hour.'-'.$min.'-'.$sec; $time_out = $year1.'-'.$month1.'-'.$day1.' '.$hour1.'-'.$min1.'-'.$sec1; $total_minutes = $total_min; $total_hour = $total_hr; $sql = "insert time (year, month, day, hour, min, sec, year1, month1, day1, hour1, min1, sec1, time_in, time_out, total_minutes, total_hour) values ('$year','$month','$day','$hour','$min','$sec','$year1','$month1','$day1','$hour1','$min1','$sec1','$time_in','$time_out', '$total_minutes', '$total_hour')";
how can add in table?
minutes
$datetime1 = strtotime($row['time_in']); //year-month-day hr:min:sec timein $datetime2 = strtotime($row['time_out']); //year-month-day hr:min:sec timeout $interval = abs($datetime2 - $datetime1); $total_min = round($interval / 60); $total_minutes = $total_min;
hour
function converttohoursmins($total_minutes, $format = '%02d:%02d') { if ($total_minutes < 1) { return; } $hours = floor($total_minutes / 60); $wmin = ($total_minutes % 60); return sprintf($format, $hours, $wmin); } $total_hr = converttohoursmins($total_minutes, '%02d hours %02d minutes'); $total_hour = $total_hr;
im new , wanted simple answer
you have convert datetime1 , datetime2 in format first :
datetime1 = 2012-01-01 12:00:00; datetime2 = 2012-01-02 13:00:00;
then in sql insert query directly insert value following functions :
timestampdiff(hour, datetime2, datetime1) // hours calculation timestampdiff(minute,datetime2, datetime1) // minutes calculation
hope may :)
Comments
Post a Comment