andrewgarn Posted June 20, 2008 Share Posted June 20, 2008 Right the requirements for my website i'm making are finding the date: <> at the beginning of this week (last monday or today if its a monday today) <> at the beginning of last week (monday) <> beginning of this month - (1st of month) <> beginning of last month - (1st of month) I can get todays date by doing: $yesterday = date("Y-m-d", strtotime("-1 days")); but i'm not sure about what to do for the rest, any ideas? Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted June 20, 2008 Author Share Posted June 20, 2008 so if this isnt very clear: today is 2008-06-20 I would want to calculate the date: the monday this week -> 2008-06-16 monday last week -> 2008-06-09 first day of this month -> 2008-06-01 first day of last month -> 2008-05-01 Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted June 20, 2008 Share Posted June 20, 2008 Maybe this will help? http://www.stroz.us/php/index.php?option=com_smf&Itemid=53&topic=94.0 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 20, 2008 Share Posted June 20, 2008 See it this helps: <?php $tmp = array(); $tmp[] = 'Today ' . date('Y-m-d') . ' is a ' . date('l'); $begweek = (date('l') == 'Monday')?date('Y-m-d'):date('Y-m-d',strtotime('last monday')); $tmp[] = 'The beginning of the week was ' . $begweek; $tmp[] = 'The beginning of last week was ' . date('Y-m-d',strtotime('-2 monday')); $tmp[] = 'The start of this month was ' . date('Y-m-01') . ', a ' . date('l',strtotime(date('Y-m-01'))); $tmp[] = 'The start of last month was ' . date('Y-m-01',strtotime('last month')) . ', a '. date('l',strtotime(date('Y-m-01',strtotime('last month')))); echo implode("<br>\n",$tmp); ?> Ken Quote Link to comment Share on other sites More sharing options...
andrewgarn Posted June 20, 2008 Author Share Posted June 20, 2008 See it this helps: <?php $tmp = array(); $tmp[] = 'Today ' . date('Y-m-d') . ' is a ' . date('l'); $begweek = (date('l') == 'Monday')?date('Y-m-d'):date('Y-m-d',strtotime('last monday')); $tmp[] = 'The beginning of the week was ' . $begweek; $tmp[] = 'The beginning of last week was ' . date('Y-m-d',strtotime('-2 monday')); $tmp[] = 'The start of this month was ' . date('Y-m-01') . ', a ' . date('l',strtotime(date('Y-m-01'))); $tmp[] = 'The start of last month was ' . date('Y-m-01',strtotime('last month')) . ', a '. date('l',strtotime(date('Y-m-01',strtotime('last month')))); echo implode("<br>\n",$tmp); ?> Ken Thank you, does exactly what i need, should be able to work out any further I need 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.