Jump to content

Recommended Posts

here is some code i use to get the next monday. maybe you can alter it for your use:

 

// Day of the week, 0-6, Sun-Sat
        $now_array = getdate($yourdateinseconds);
$wday = $now_array["wday"];

// Number of days back to the Monday to be displayed:
switch ($wday) {
	case 0: {
		$daysBack = 6;
		$daysForward = 0;
		break;
	}
	case 1: {
		$daysBack = 0;
		$daysForward = 6;
		break;
	}
	case 2: {
		$daysBack = 1;
		$daysForward = 5;
		break;
	}
	case 3: {
		$daysBack = 2;
		$daysForward = 4;
		break;
	}
	case 4: {
		$daysBack = 3;
		$daysForward = 3;
		break;
	}
	case 5: {
		$daysBack = 4;
		$daysForward = 2;
		break;
	}
	case 6: {
		$daysBack = 5;
		$daysForward = 1;
		break;
	}
}

// Subtract daysBack to get the start date for this calendar
$monTime = mktime($now_array["hours"],$now_array["minutes"],$now_array["seconds"],$now_array["mon"],$now_array["mday"]-$daysBack,$now_array["year"]);

$endTime = mktime($now_array["hours"],$now_array["minutes"],$now_array["seconds"],$now_array["mon"],$now_array["mday"]- $daysBack + 6,$now_array["year"]);

 

$monTime is the previous Monday, in seconds. $endTime is the following Sunday, in seconds.

Link to comment
https://forums.phpfreaks.com/topic/105267-solved-date-question/#findComment-539016
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.