There was a question asked to myself how to know the number of days that calculated from Monday until today of this week by using PHP script. Well, actually, we can make a function by checking based on the day name of today, then return the value based on its day name to the function. So here is the solution I made.
Create a php file named daysnumber.php, and copy-paste this following code into it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | <?php /** * @author Masino Sinaga, http://www.openscriptsolution.com * @copyright December 13, 2009 */ $days = DaysNumberStartedFromMondayUntilTodayThisWeek(); echo 'The number of days from Monday until today is <b>'.$days.'</b> day(s).'; function DaysNumberStartedFromMondayUntilTodayThisWeek() { $dayname = date('D'); switch ($dayname) { case 'Sun': $days = 6; break; case 'Mon': $days = 0; break; case 'Tue': $days = 1; break; case 'Wed': $days = 2; break; case 'Thu': $days = 3; break; case 'Fri': $days = 4; break; case 'Sat': $days = 5; break; } return $days; } ?> |

Recent Comments