Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the last thursday before a date in PHP

Tags:

date

php

datetime

I know there is similar post about how to get the last Thursday in PHP but I don't want to have the last Thursday compare to the current date but the last Thursday compare to a given date.

For example I have a date dd/mm/yyyy and I want the Thursday before this date. The input is a String ( the format of the string yymmdd) that I want to parse to get the Thursday before this date.

Thanks for your help

like image 841
Othman Avatar asked Oct 23 '25 01:10

Othman


1 Answers

//Assumes it's strtotime parsable, you may need to insert
//  slashes with your given format eg (and use 4 digit years)
$given=strtotime($dtstring);

//It's just that easy ;)
$thuBefore=strtotime("last thursday",$given);

Note that this will always get last thursday, meaning if the given date is a Thursday, it'll report 7 days earlier (but if the date's a Friday it'll only report one day earlier).

like image 93
Rudu Avatar answered Oct 25 '25 16:10

Rudu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!