The first_tuesday()
function should return the date of the first Tuesday of year, but especially in the case of 2011 it returns a wrong value. how to Fix the code so it works in all cases
function first_tuesday($year){
$first_january = mktime(0,0,0,1,1,$year);
$day_week = date("w",$first_january );
$first_tuesday = $first_jan + ((2 - $day_week) % 7)* 86400;
return date("d/m/Y",$first_tuesday);
}
strtotime
is clever enough to get what you want:
function first_tuesday($year){
return date('d/m/Y', strtotime("first Tuesday of January $year"));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With