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
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;

}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.