RIRedinPA Posted January 13, 2011 Share Posted January 13, 2011 I got a snippet of code from here that will give me the Monday of any submitted date, so if I pass 12/08/10 it'll return 12/06/10 as the Monday, which is correct. I tried to expand it to give me the Tuesday of that week: function getWeekDays($date) { $offset = ''; if( date('l', strtotime($date)) == 'Monday' ) { $offset = ''; } elseif( date('l', strtotime($date)) == 'Sunday' ) { $offset = 'Tomorrow'; } else { $offset = 'Last Monday'; } $monday = date('m/d/Y', strtotime("$date $offset")); $tuesday = date('m/d/Y', strtotime("+1 day", $monday)); return $tuesday; } I keep getting the UNIX epoch returned for $tuesday...obviously this is just confusing the crap out of me, could someone explain what it is I am doing wrong? Thanks Link to comment https://forums.phpfreaks.com/topic/224339-still-stuck-on-date-stuff/ Share on other sites More sharing options...
AbraCadaver Posted January 13, 2011 Share Posted January 13, 2011 $tuesday = date('m/d/Y', strtotime("+1 day", strtotime($monday))); Link to comment https://forums.phpfreaks.com/topic/224339-still-stuck-on-date-stuff/#findComment-1159007 Share on other sites More sharing options...
BLaZuRE Posted January 13, 2011 Share Posted January 13, 2011 This might help you out: http://php.net/manual/en/function.date.php and http://www.php.net/manual/en/function.strtotime.php function getWeekDays($date) { $offset = ''; if( date('l', strtotime($date)) == 'Monday' ) { //If $date is a Monday, blank offset $offset = ''; } elseif( date('l', strtotime($date)) == 'Sunday' ) { //If $date is a Sunday, offset says Tomorrow is Monday $offset = 'Tomorrow'; } else { //If $date is not a Sunday or Monday, offset says Last Monday to get the last Monday $offset = 'Last Monday'; } $monday = date('m/d/Y', strtotime("$date $offset")); //Displays both $date and $offset (i.e. "01/13/2011LastMonday" $tuesday = date('m/d/Y', strtotime("+1 day", $monday)); //$monday must be an integer timestamp return $tuesday; } Link to comment https://forums.phpfreaks.com/topic/224339-still-stuck-on-date-stuff/#findComment-1159008 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.