在PHP的日期之前获得最后一个星期四

Oth*_*man 3 php datetime date

我知道有类似的帖子关于如何在PHP的最后一个星期四,但我不想让最后一个星期四与当前日期相比,但是最后一个星期四与给定日期相比.

例如,我有一个日期dd/mm/yyyy,我希望在此日期之前的星期四.输入是一个String(字符串yymmdd的格式),我要解析它以获取此日期之前的星期四.

谢谢你的帮助

Rud*_*udu 8

//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);
Run Code Online (Sandbox Code Playgroud)

请注意,这将始终是最后一个星期四,这意味着如果给定日期是星期四,它将提前7天报告(但如果日期是星期五,它只会提前一天报告).