Jump to content

php date functions, trouble finding last day of month


juanc

Recommended Posts

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 4

What 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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.