Jump to content

Still stuck on date() stuff...


RIRedinPA

Recommended Posts

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

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;

}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.