From: justino garcia on
HOw would I use this function below, from this url
http://php.net/manual/en/function.date-diff.php
I need to output the subject, date, and the final answer to the calcuation
of the time difference (say from e.g. 10:00 AM to 12:00 PM) . Getting total
time wrked on at a job site, doing helpdesk. I am doing this for me to send
a preformated email to acounting, it will help since I am busy at work and
suck at counting time worked due to my adhd and dyslxia.
Thanks
<http://php.net/manual/en/function.date-diff.php>





This function calculates the difference up to the second.

<?php

function date_diff($start, $end="NOW")
{
$sdate = strtotime($start);
$edate = strtotime($end);

$time = $edate - $sdate;
if($time>=0 && $time<=59) {
// Seconds
$timeshift = $time.' seconds ';

} elseif($time>=60 && $time<=3599) {
// Minutes + Seconds
$pmin = ($edate - $sdate) / 60;
$premin = explode('.', $pmin);

$presec = $pmin-$premin[0];
$sec = $presec*60;

$timeshift = $premin[0].' min '.round($sec,0).' sec ';

} elseif($time>=3600 && $time<=86399) {
// Hours + Minutes
$phour = ($edate - $sdate) / 3600;
$prehour = explode('.',$phour);

$premin = $phour-$prehour[0];
$min = explode('.',$premin*60);

$presec = '0.'.$min[1];
$sec = $presec*60;

$timeshift = $prehour[0].' hrs '.$min[0].' min '.round($sec,
0).' sec ';

} elseif($time>=86400) {
// Days + Hours + Minutes
$pday = ($edate - $sdate) / 86400;
$preday = explode('.',$pday);

$phour = $pday-$preday[0];
$prehour = explode('.',$phour*24);

$premin = ($phour*24)-$prehour[0];
$min = explode('.',$premin*60);

$presec = '0.'.$min[1];
$sec = $presec*60;

$timeshift = $preday[0].' days '.$prehour[0].' hrs '.$min[0
].' min '.round($sec,0).' sec ';

}
return $timeshift;
}

// EXAMPLE:

$start_date = 2010-03-15 13:00:00
$end_date = 2010-03-17 09:36:15

echo date_diff($start_date, $end_date);

?>


*MY
CODE-------------------------------------------------------------------------------===============================--------------------------------
*

"<html><body>

Hello there TechSquad!<br >

<form action="process.php" method="post">
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name="item">
<option selected>MLS</option>
<option>ITS</option>
<option>JCPA</option>
<option>Kocher</option>
<option>Bagel Buffet</option>
<option>Warranty Title</option>
<option>Metalico</option>
</select> </p>
<p>Date:&nbsp;&nbsp;&nbsp;&nbsp; <input type="'text"
name=date ??></p>
<p>Subject: <input name="quantity" style="WIDTH: 280px; HEIGHT: 25px"
size="27"> </p>
<p>

<select name=StartTime>
<?php
$hours = range(0, 12);
$mins = range(0, 59, 15);
$time = array();

foreach ($hours as $h)
{
foreach ($mins as $m)
{
$val = sprintf("%02d:%02d"." AM", $h, $m);
$time[$val] = $val;
echo '<option>' . $time[$val] . '</option>' .
"\n";
}
}
?>
</select>
<select name=EndTime>
<?php
$hours = range(1, 12);
$mins = range(0, 59, 15);
$time = array();

foreach ($hours as $h)
{
foreach ($mins as $m)
{
$val = sprintf("%02d:%02d"." PM", $h, $m);
$time[$val] = $val;
echo '<option>' . $time[$val] . '</option>' .
"\n";
}
}
?>
</select>
<textarea style="Z-INDEX: 0; WIDTH: 343px; HEIGHT: 163px; TOP: 258px; LEFT:
15px" rows="6" cols="27" name="body_email">Enter the work done
here.</textarea></p>
<p><input value="Submit Query" type="submit">
</p></form></body></html>

--
Justin
IT-TECH



--
Justin
IT-TECH