- To determine whether the same week
date_default_timezone_set ( 'PRC' ); // determine whether the same week, the principle: find one where the timestamp of the week Monday morning and Sunday 24.00 timestamp timestamp, if another time stamps within this range, then in the same week, the same week otherwise not function getSameWeek ( $ pretime , $ AFTERTIME ) { $ monday = strtotime ( 'last catalog on Monday', $ pretime ); // from the current time stamp on a Monday timestamp $ pretime recent, if the current time $ pretime Monday, $ monday storage remains last Monday // determine if the current time stamp is given on Monday it returns the current timestamp monday to $ IF ( DATE ( 'w', $ pretime )) { $ Monday = $ PRETime ; } $ Sunday = $ Monday + 24 * 3600 *. 7; //Sun stamp IF ( $ AFTERTIME > = $ Sunday ) { return to false ; } IF ( $ AFTERTIME <= $ Monday ) { return to false ; } return to true ; } $ testWeek_start = strtotime ( '2019-8-19' ); testWeek_end $ = strtotime ( '2019-8-18' ); echo getSameWeek ( $ testWeek_start , $ testWeek_end ) 'in the same week':? 'not in the same week', '<br>';
- To determine whether the same month (use the above ideas can be implemented, but here the use of another idea)
date_default_timezone_set ( 'a PRC' ); function isSameMonth ( $ TIME1 , $ TIME2 ) { $ M1 = DATE ( 'Ym of', $ TIME1 ); $ M2 = DATE ( 'Ym of', $ TIME2 ); // year must be determined, or 2019-8 and 2020-8 will be considered in the same month IF ( $ M1 == $ M2 ) { return to true ; } return to false ; } $ T1 = strtotime ( '2018-8-13' ); $ T2 = strtotime( '2019-8-18' ); echo isSameMonth ( $ T1 , $ T2 ) 'in the same month':? 'Not on the same month';
- On determination using a relatively simple determination dated idea, just the date in the '' m '' removed, the code will be omitted
PHP to determine whether a given two times in the same week, month, year
Guess you like
Origin www.cnblogs.com/bneglect/p/12036834.html
Recommended
Ranking