note 96385 modified in function.strtotime by danbrown

From: Date: Wed, 24 Feb 2010 16:10:35 +0000
Subject: note 96385 modified in function.strtotime by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166322@lists.php.net to get a copy of this message
A handy function I wrote to tell you whether a given date (unix timestamp) is a working day in the UK. i.e. not a bank holiday or weekend day. Returns true or false. <?php function isUkWorkingDay( $utDate ) { /* weekend? */ if( date( 'N', $utDate ) > 5 ){ return false; } /* bank holiday? */ $year = date( 'Y', $utDate ); $utFirstJan = strtotime( '1st jan ' . $year ); $firstJanDay = date( 'N', $utFirstJan ); if ( $firstJanDay > 5 ){ // sat or sun $holidays[] = date( 'Y-m-d', strtotime( 'first monday january ' . $year )); } else{ $holidays[] = date( 'Y-m-d', $utFirstJan) ; } $utEasterSunday = easter_date( $year ); $holidays[] = date( 'Y-m-d', strtotime( 'last friday', $utEasterSunday )); $holidays[] = date( 'Y-m-d', strtotime( 'next monday', $utEasterSunday )); $holidays[] = date( 'Y-m-d', strtotime( 'first monday may ' . $year )); $holidays[] = date( 'Y-m-d', strtotime( 'last monday june ' . $year )); // end of may B.H. $holidays[] = date( 'Y-m-d', strtotime( 'last monday september ' . $year )); // end of August B.H. $xmasDay = date( strtotime( '25th december ' . $year ) ); if ( date( 'N', $xmasDay ) == 5 ){ // falls on friday $holidays[] = date( 'Y-m-d', $xmasDay ); $holidays[] = date( 'Y-m-d', strtotime( 'next monday', $xmasDay )); } if ( date( 'N', $xmasDay ) > 5 ){ // falls on sat or sun $holidays[] = date( 'Y-m-d', strtotime( 'next monday', $xmasDay )); $holidays[] = date( 'Y-m-d', strtotime( 'next tuesday', $xmasDay )); } if ( date( 'N', $xmasDay ) < 5 ){ // falls on mon to thurs $holidays[] = date( 'Y-m-d', $xmasDay ); $holidays[] = date( 'Y-m-d', strtotime( 'next day', $xmasDay )); } return( !in_array( date( 'Y-m-d', $utDate ), $holidays ) ) ; } ?> --was-- A handy function I wrote to tell you whether a given date (unix timestamp) is a working day in the UK. i.e. not a bank holiday or weekend day. Returns true or false. <?php function isUkWorkingDay( $utDate ) { /* weekend? */ if( date( 'N', $utDate ) > 5 ){ return false; } /* bank holiday? */ $year = date( 'Y', $utDate ); $utFirstJan = strtotime( '1st jan ' . $year ); $firstJanDay = date( 'N', $utFirstJan ); if ( $firstJanDay > 5 ){ // sat or sun $holidays[] = date( 'Y-m-d', strtotime( 'first monday january ' . $year )); } else{ $holidays[] = date( 'Y-m-d', $utFirstJan) ; } $utEasterSunday = easter_date( $year ); $holidays[] = date( 'Y-m-d', strtotime( 'last friday', $utEasterSunday )); $holidays[] = date( 'Y-m-d', strtotime( 'next monday', $utEasterSunday )); $holidays[] = date( 'Y-m-d', strtotime( 'first monday may ' . $year )); $holidays[] = date( 'Y-m-d', strtotime( 'last monday june ' . $year )); // end of may B.H. $holidays[] = date( 'Y-m-d', strtotime( 'last monday september ' . $year )); // end of August B.H. $xmasDay = date( strtotime( '25th december ' . $year ) ); if ( date( 'N', $xmasDay ) == 5 ){ // falls on friday $holidays[] = date( 'Y-m-d', $xmasDay ); $holidays[] = date( 'Y-m-d', strtotime( 'next monday', $xmasDay )); } if ( date( 'N', $xmasDay ) > 5 ){ // falls on sat or sun $holidays[] = date( 'Y-m-d', strtotime( 'next monday', $xmasDay )); $holidays[] = date( 'Y-m-d', strtotime( 'next tuesday', $xmasDay )); } if ( date( 'N', $xmasDay ) < 5 ){ // falls on mon to thurs $holidays[] = date( 'Y-m-d', $xmasDay ); $holidays[] = date( 'Y-m-d', strtotime( 'next day', $xmasDay )); } return( !in_array( date( 'Y-m-d' ), $holidays ) ) ; } ?> http://php.net/manual/en/function.strtotime.php

« previous php.notes (#166322) next »