juanc Posted August 19, 2006 Share Posted August 19, 2006 With regards to the numerical value of each day of the week.ie. Sunday is 0,Monday is 1,Tuesday is 2 and so on.I need the value for the day of the week that falls on the last day of the month. For example this month being August ……….so 31 Aug falls on a Thursday so that would be 4What I’ve written doesn’t work properly. [code]<?php$month = date('n');$year = date('Y');$timestamp = mktime(0,0,0,$month,1,$year);$numOfdays = date('t',$timestamp);$lastDayDate = mktime(0,0,0,$month,$numOfdays,$year);$lastDayNumber = date('w',$lastDayDate);echo 'The number is ' . $lastDayNumber;?>[/code]This actually works but if I change to being in respect this coming September ($timestamp = mktime(0,0,0,9,1,$year);it gives me 3 when it should be 6 as 30 Sep falls on a Saturday. Similarly with October I get 4 when it should be 2 as 31 Oct falls on a Tuesday. Link to comment https://forums.phpfreaks.com/topic/18045-php-date-functions-trouble-finding-last-day-of-month/ Share on other sites More sharing options...
AndyB Posted August 19, 2006 Share Posted August 19, 2006 [code]<?phplist($y,$m,$d) = explode("-", date("Y-m-d")); // get current month and yearecho date("w", mktime(0,0,0,$m+1,0,$y)); // day before first day of next month?>[/code] Link to comment https://forums.phpfreaks.com/topic/18045-php-date-functions-trouble-finding-last-day-of-month/#findComment-77316 Share on other sites More sharing options...
litebearer Posted August 19, 2006 Share Posted August 19, 2006 Try this...[code]<?PHP$mo=8;$year = 2006;echo date('w',strtotime($mo . "/" . date('t',strtotime($mo . "/" . "28" . "/" . $year)) . "/" . $year));?>[/code]Lite...day late and dollar short Link to comment https://forums.phpfreaks.com/topic/18045-php-date-functions-trouble-finding-last-day-of-month/#findComment-77317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.