Jump to content

[SOLVED] Date question


jeff5656

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

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.