I have built a countdown timer on my site which counts down the days left until the listing expires so that the clients and designers have an efficient way of keeping track of a project. When the designers are not in the office on weekends is there any way that I would be able to stop the timer when the day is a weekend?
<?php
//start date
//end date
//echo date('yy-m-d H:i:s', strtotime($data->created));
$date2 = date('yy-m-d H:i:s', strtotime($data->created . '+ '. $days));
//echo '<br>'. $date2;
$date = gmdate('U', strtotime($date2));
//echo '<br>'. $date;
//echo '<br>' .time();
$remaining = $date - time();
//echo '<br>r=' . $remaining ; //get_option('date_format');2020-04-27 14:58:28
// Get difference between both dates without DST
$diff = $date - gmdate('U');
// Days (in last day it will be zero)
$diff_days = floor($remaining / (24 * 60 * 60));
// Hours (in the last hour will be zero)
$diff_hours = floor($remaining % (24 * 60 * 60) / 3600);
if( $remaining >= 0 )
{
$days_remaining = floor($remaining / 86400);
$hours_remaining = floor(($remaining % 86400) / 3600);
$minutes_remaining = floor(($remaining % 3600) / 60);
/*make red on last day*/
$style = '';
if($days_remaining < 1 or $days_remaining == 1 && $hours_remaining == 0){
$style = 'style="color:#fb3a5e;"';
echo 'Today';
}
else
{
echo '<span '.$style.'>'. $diff_days .' days and '. $diff_hours .' hours left</span>';
}
}
else
{
echo 'Expired.';
}
?>