Archive

Posts Tagged ‘time’

Time Compare Between Times

$shiftInTime = strtotime($shiftInTime);
$punchInTime = strtotime($punchInTime);
if($shiftInTime <= $punchInTime)
{ Echo $present = ‘present’;}
Else
{ Echo “Absence”;
}

Categories: Date Time, PHP Tags: ,

Time Difference between times ( start time and end time )

// an START time value
$start = ’09:00′;
// an END time value
$end = ’10:30′;

// what is the time difference between $end and $start?
if( $diff=@get_time_difference($start, $end) )
{
echo “Hours: ” .
sprintf( ‘%02d:%02d’, $diff[‘hours’], $diff[‘minutes’] );
}
else
{
echo “Hours: Error”;
}

//Call function for time diff

function get_time_difference( $start, $end )
{ $uts[‘start’] = strtotime( $start );
$uts[‘end’] = strtotime( $end );
if( $uts[‘start’]!==-1 && $uts[‘end’]!==-1 )
{
if( $uts[‘end’] >= $uts[‘start’] )
{
$diff = $uts[‘end’] – $uts[‘start’];
if( $days=intval((floor($diff/86400))) )
$diff = $diff % 86400;
if( $hours=intval((floor($diff/3600))) )
$diff = $diff % 3600;
if( $minutes=intval((floor($diff/60))) )
$diff = $diff % 60;
$diff = intval( $diff );
return( array(‘days’=>$days, ‘hours’=>$hours, ‘minutes’=>$minutes, ‘seconds’=>$diff) );
}
else
{
trigger_error( “Ending date/time is earlier than the start date/time”, E_USER_WARNING );
}
}
else
{
trigger_error( “Invalid date/time data detected”, E_USER_WARNING );
}
return( false );
}

Categories: Date Time, PHP Tags: ,

Get First day of input dates and last day of input date

$mydate = ‘2011-02-04’;

//Get First Day date from given date
echo date(“Y-m-1”, strtotime($mydate) ) ;

//Get Last Day date from given date
echo date(“Y-m-t”, strtotime($mydate) ) ;

Categories: Date Time, PHP Tags: ,

Compare Two Dates

$date1 = “2011-03-23”;
$date2 = date(“Y-m-d”);
function twoDateCompareEqualOrNot($date1,$date2)
{
$date1 = strtotime($date1);
$date2 = strtotime($date2);
if ($date1 == $date2) {
return true;
}
else {
return false;
}
}

Categories: Date Time, PHP Tags: ,