Jump to content

How To Find Monday Of A Given Week


refiking

Recommended Posts

I've googled for this but have only found scripts that require you to given them a specific date and it tells you what day that is.  I need something that can take a date in Y-m-d format and give me the date of the Monday of that week. Here's where I am right now:

$time = time();
$today = date('Y-m-d 00:00:00', $time);
//$monday = ????

Link to comment
https://forums.phpfreaks.com/topic/131389-how-to-find-monday-of-a-given-week/
Share on other sites

Thanks Ken.  I already got something working based on the link F1Fan gave me.  Although yours is a bit less verbose.  Here's what I did:

IF ($day = 'Monday'){
$mon = strtotime("$today");
$tue = strtotime("$today + 1 day");
$wed = strtotime("$today + 2 days");
$thur = strtotime("$today + 3 days");
$fri = strotime("$today + 4 days");
}
IF ($day = 'Tuesday'){
$mon = strtotime("$today - 1 day");
$tue = strtotime("$today");
$wed = strtotime("$today + 1 day");
$thur = strtotime("$today + 2 days");
$fri = strtotime("$today + 3 days");
}
IF ($day = 'Wednesday'){
$mon = strtotime("$today - 2 days");
$tue = strtotime("$today - 1 day");
$wed = strtotime("$today");
$thur = strtotime("$today + 1 day");
$fri = strtotime("$today + 2 days");
}
IF ($day = 'Thursday'){
$mon = strtotime("$today - 3 days");
$tue = strtotime("$today - 2 days");
$wed = strtotime("$today - 1 day");
$thur = strtotime("$today");
$fri = strtotime("$today + 1 day");
}
IF ($day = 'Friday'){
$mon = strtotime("$today -  4 days");
$tue = strtotime("$today - 3 days");
$wed = strtotime("$today - 2 days");
$thur = strtotime("$today - 1 day");
$fri = strtotime("$today");
}
IF ($day = 'Saturday'){
$mon = strtotime("$today -  5 days");
$tue = strtotime("$today - 4 days");
$wed = strtotime("$today - 3 days");
$thur = strtotime("$today - 2 days");
$fri = strtotime("$today - 1 day");
}
IF ($day = 'Sunday'){
$mon = strtotime("$today = 1 day");
$tue = strtotime("$today + 2 days");
$wed = strtotime("$today + 3 days");
$thur = strtotime("$today + 4 days");
$fri = strtotime("$today + 5 days");
}

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.