检查重复日期 [英] Check for repeating dates

查看:110
本文介绍了检查重复日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用PHP创建一个日历,并且在数据库中有一个日期,例如10-10-6。

I am creating a calendar in PHP and in the database have a date, let's say 6-10-10.

有时我有重复的事件,每周存储一次重复,所以如果日期是6-10-10,而我要从那天(包括那天)起每两周重复一次事件,什么是从6-10-10开始每两周查找日期的最佳方法是什么?

Sometimes I have repeating events, stored as weekly repeating, so if the date is 6-10-10, and I am repeating an event every two weeks from that day (including that day) what is the best way to find dates for every two weeks from 6-10-10?

例如,假设日期为7-8-10,如何检查日期是否符合我的条件?

For example, let's say the date is 7-8-10, how can I check to see that date meets my criteria?

推荐答案

循环是怎么回事?!离散数学101:如何计算数字是否为偶数? n%2 == 0

What's up with the looping?! Discrete Math 101: How do you figure out if a number is even? n%2==0

您如何确定日期是否是两周一次? date%2weeks == 0

How do you figure out if a date is (uh...) biweekly? date%2weeks==0

折腾而后得到(date- startdate)%2weeks

$startdate = strtotime("10 June 2010");
$otherdate = strtotime("8 July 2010");
$twoweeks  = strtotime("+2 weeks") - time();
if($otherdate>$startdate && (($otherdate-$startdate)%$twoweeks)==0) {
    // this is n * two weeks after
}

这篇关于检查重复日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆