Description of requirements:
Determine whether it is a bi-weekly or single-week holiday based on the date of every Saturday. That is, if the date on Saturday is an odd number, then this week is an odd-week holiday; if it is an even number, it is a double-week holiday.
Before, we did not take into account the issue of the different number of days in each month, resulting in an inaccurate judgment. After modification, it is now accurate.
Example, PHP gets the date of every Saturday and PHP determines odd and even numbers implementation code.
-
- $ts=date('t');//Get the total number of days in this month
- $rq=date('d');//Get today's date
- $xq=date ('w');//Get today's week, 1-6 represents week 1-6, 0 represents Sunday
- //Calculate the number of days to Saturday
- if ($xq==6){
- $date1= 0;
- }else if ($xq==0){
- $date1= -1;
- }else{
- $date1= 6-$xq;}
- //Use the current date plus the number of days until Saturday
- $rq=$rq+$date1;
- //Compare with the total number of days in this month
- if ($rq <= $ts){
- $rq=$rq;
- }else if($rq > $ts){
- $rq=$rq-$ts;
- }else{
- $rq=$date1;
- } bbs.it-home.org
- //Get the calculated Saturday date, and then judge whether the date is odd or even.
- $a=$rq;
- $a= $a%2;
- if ($a==0){
- echo 'This Saturday is: '.$rq.', this week is a fortnight';
- }
- else{
- echo 'This Saturday is: '.$rq.' number, this week is a single week';
- }
- ?>
Copy code
|