Jump to content

Computing day of week


AV1611

Recommended Posts

There is a php function to calculate the current day of the week mcal_day_of_week( int year, int month, int day ) (<a href="http://php.belnet.be/manual/en/function.mcal-day-of-week.php">see php manual</a>) and returns the day of the week of the given date. Possible return values range from 0 for Sunday through 6 for Saturday.

For ex.
[code]
$day_of_week_today = mcal_day_of_week(strftime('%Y'), strftime('%m'), strftime('%d'));
$previous_sundag = date('Y-m-d', mktime('', '', '', strftime('%m'), strftime('%d') - $day_of_week_today, strftime('%Y'));
[/code]

Link to comment
https://forums.phpfreaks.com/topic/13839-computing-day-of-week/#findComment-53840
Share on other sites

You can also get the date of the last sunday by using the date() and strtotime() functions:
[code]<?php
$dt = (isset($_GET['d'])?date('Y-m-d',strtotime('last sunday')):date('Y-m-d',strtotime('last sunday',strtotime($_GET['d'])));
echo $dt;
?>[/code]

Ken
Link to comment
https://forums.phpfreaks.com/topic/13839-computing-day-of-week/#findComment-53848
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.