获取PHP之前的最后一个星期四 [英] get the last thursday before a date in PHP
问题描述
我知道有关于如何在PHP中获得最后一个星期四的相似文章,但是我不想让最后一个星期四与当前日期相比较,但上周四比较给定日期。
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.
例如我有一个日期dd / mm / yyyy,我想在这个日期之前的星期四。
输入是一个字符串(字符串yymmdd的格式),我想解析以获取此日期之前的星期四。
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.
感谢您的帮助
推荐答案
//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);
请注意,这将永远获得上一个星期四,这意味着如果给定的日期是星期四,它会在7天前报告(但如果日期是星期五,那只会在前一天提前报告)。
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).
这篇关于获取PHP之前的最后一个星期四的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!