[英]how can i get all next dates with day from given date which is based on weekly, biweekly, monthly in php?
我希望從指定日期開始的所有下一個日期與日期一起在cron
作業文件中發送郵件。 現在我正在通過計算來檢查它的星期
$event_from_date = strtotime(date('Y-m-d',strtotime($rs->from_date)));
$today_date = strtotime(date('Y-m-d'));
$event_expire_on = strtotime($rs->to_date);
if($rs->time_zone == "CST")
$current_date=strtotime($cst_date);
elseif($rs->time_zone == "PST")
$current_date=strtotime($pst_date);
elseif($rs->time_zone == "MST")
$current_date=strtotime($est_date);
elseif($rs->time_zone == "EST")
$current_date=strtotime($mst_date);
if($current_date <= $event_expire_on && $current_date >= $event_from_date)
{
$diff=$today_date-$event_from_date;
if($diff%604800 == 0 && $rs->report_cycle=="Weekly")
$flag = 1;
else
$flag = 0;
}
有誰能告訴我。 如何獲取每周的下一個7天,雙周的15天,每月的30天以及周一,周二的日期。
我不確定100%知道您的問題。 DateTime類提供了以各種方式操縱日期和時間的簡單方法。
我認為,在您的位置上,我將尋找DatePeriods來代表我需要的各種erm,句點。 這樣的功能可能適合:
/**
* @param Int $days
* @return DatePeriod
*/
function getNumDays($days)
{
$today = new \DateTime('UTC');
$oneDay = new \DateInterval('P1D');
return new \DatePeriod($today, $oneDay, $days);
}
foreach(getNumDays(7) as $day){
//Do what ever you want with the DateTime instance
//We'll just var_dump() it for now.
var_dump($day);
}
看到它工作 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.