AV1611 Posted July 6, 2006 Share Posted July 6, 2006 I have a script that needs to use a date range. the starting date is not important, but the ending date is always the date of the last sunday before today.Is there a way to compute the date of last sunday automatically? Link to comment https://forums.phpfreaks.com/topic/13839-computing-day-of-week/ Share on other sites More sharing options...
CheesierAngel Posted July 6, 2006 Share Posted July 6, 2006 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 More sharing options...
obsidian Posted July 6, 2006 Share Posted July 6, 2006 can't you just use strtotime? try something like this and see if it helps:[code]<?phpecho date('Y-m-d', strtotime("last Sunday"));?>[/code] Link to comment https://forums.phpfreaks.com/topic/13839-computing-day-of-week/#findComment-53846 Share on other sites More sharing options...
kenrbnsn Posted July 6, 2006 Share Posted July 6, 2006 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.