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? Quote Link to comment 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] Quote Link to comment 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] Quote Link to comment 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 Quote Link to comment 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 ;) Quote Link to comment 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! ;) Quote Link to comment Share on other sites More sharing options...
Cep Posted January 24, 2007 Author Share Posted January 24, 2007 Thanks everyone :) Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.