简体   繁体   English

我如何获得给定日期的某天的所有下一个日期,该日期基于php中的每周,每两周,每月?

[英]how can i get all next dates with day from given date which is based on weekly, biweekly, monthly in php?

I want all next dates with day from specified date for sending mail within cron job file. 我希望从指定日期开始的所有下一个日期与日期一起在cron作业文件中发送邮件。 right now I m checking for whether its week by calculating like this 现在我正在通过计算来检查它的星期

$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;
} 

can any body tell me . 有谁能告诉我。 how can I get all next 7 days for weekly,15 days for biweekly,30 days for monthly with its day like Monday,Tuesday.. 如何获取每周的下一个7天,双周的15天,每月的30天以及周一,周二的日期。

I'm not 100% sure I have understood your question. 我不确定100%知道您的问题。 The DateTime classes offer simple ways of manipulating dates and times in all manner of ways. DateTime类提供了以各种方式操纵日期和时间的简单方法。

I think, in your position I would be looking for DatePeriods to represent the various erm, periods I need. 我认为,在您的位置上,我将寻找DatePeriods来代表我需要的各种erm,句点。 A function like this may suit:- 这样的功能可能适合:

/**
 * @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);
}

See it working . 看到它工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM