Cep Posted January 24, 2007 Share Posted January 24, 2007 Hello,This is a quick question but how would I go about returning the last Sunday's date in the week from the time the user views the page?Would I use getdate() or time() with some sort of +/- combination? Link to comment https://forums.phpfreaks.com/topic/35533-get-previous-sunday/ Share on other sites More sharing options...
Jessica Posted January 24, 2007 Share Posted January 24, 2007 [code]<?php//Get today$dayInWeek = date("N");$theDay = time();//Subtract days until it's the 7th day, Sundaywhile($dayInWeek != 7){ $theDay = $theDay-(24*60*60); $dayInWeek = date("N");}//The last Sunday was $theDay;print date("m-d-Y", $theDay);?>[/code] Link to comment https://forums.phpfreaks.com/topic/35533-get-previous-sunday/#findComment-168210 Share on other sites More sharing options...
mjlogan Posted January 24, 2007 Share Posted January 24, 2007 [code=php:0]return date("l, jS F, Y", strtotime("last sunday", time()));[/code] Link to comment https://forums.phpfreaks.com/topic/35533-get-previous-sunday/#findComment-168215 Share on other sites More sharing options...
kenrbnsn Posted January 24, 2007 Share Posted January 24, 2007 I would use the [url=http://www.php.net/strtotime]strtotime()[/url] function:[code]<?phpecho 'Today is ' . date('l, F j, Y'). '<br>';echo 'The previous Sunday was ' . date('l, F j, Y',strtotime('previous sunday')) . '<br>';echo 'Next Sunday is ' . date('l, F j, Y',strtotime('this sunday'));?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/35533-get-previous-sunday/#findComment-168216 Share on other sites More sharing options...
Jessica Posted January 24, 2007 Share Posted January 24, 2007 [quote author=mjlogan link=topic=123847.msg512433#msg512433 date=1169657458][code=php:0]return date("l, jS F, Y", strtotime("last sunday", time()));[/code][/quote]I feel like such a doofus. That is a much easier, faster way to do it. Kudos ;) Link to comment https://forums.phpfreaks.com/topic/35533-get-previous-sunday/#findComment-168218 Share on other sites More sharing options...
mjlogan Posted January 24, 2007 Share Posted January 24, 2007 [quote author=jesirose link=topic=123847.msg512436#msg512436 date=1169657549][quote author=mjlogan link=topic=123847.msg512433#msg512433 date=1169657458][code=php:0]return date("l, jS F, Y", strtotime("last sunday", time()));[/code][/quote]I feel like such a doofus. That is a much easier, faster way to do it. Kudos ;)[/quote]I have just written a massive system that does a lot of processing of data based around dates. Daylight saving time is fun to work with! ;) Link to comment https://forums.phpfreaks.com/topic/35533-get-previous-sunday/#findComment-168223 Share on other sites More sharing options...
Cep Posted January 24, 2007 Author Share Posted January 24, 2007 Thanks everyone :) Link to comment https://forums.phpfreaks.com/topic/35533-get-previous-sunday/#findComment-168224 Share on other sites More sharing options...
Jessica Posted January 24, 2007 Share Posted January 24, 2007 My way was enterprisey :)You know they just changed DST in the US? It's going to start on a different date than it used to. Link to comment https://forums.phpfreaks.com/topic/35533-get-previous-sunday/#findComment-168226 Share on other sites More sharing options...
mjlogan Posted January 24, 2007 Share Posted January 24, 2007 British system :P as long as PHP informs the script correctly it should all nicely plod along. Link to comment https://forums.phpfreaks.com/topic/35533-get-previous-sunday/#findComment-168233 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.