根据当前日期在 PHP 中创建重复日期,并使用布尔值表示完成或未完成
Ello,
我在 PHP/MySql 中遇到一些日期问题。我有一个表格,提供每年、每季度、每月、每两周或每周一次的付款,我需要能够跟踪付款时间。
因此,例如,如果在 3 月 8 日星期一(即输入的日期)添加某些内容,则每周四重复一次(用户只会看到提供一周中的几天的下拉列表 - 因为重复是每周),那么它会在数据库中输入 52 个(每周)到期日(朱利安/任何最简单的日期),并标记其中的前 9 个已付款(因为那些日子已经过去了);其余的进入但标记为未付款。
我有一个表,其中包含每个 due_date 条目、付款详细信息的链接以及已付/未付的布尔字段。
因此,在上面的示例中,付款表将类似于:
id | pmnt_id | due_date | is_paid
1 | 0023 | 01/07/10 | 1
2 | 0023 | 01/14/10 | 1
3 | 0023 | 01/21/10 | 1
10 | 0023 | 03/25/10 | 0
11 | 0023 | 04/01/10 | 0
等等...
问题是,嗯,一切。日历系统是如此的糟糕,以至于似乎没有真正的逻辑/直接的方法来做到这一点。我整个早上都在绞尽脑汁,搜索护目镜和 php 日期手册,我只是变得更加困惑。
任何想法/建议/指示将不胜感激。
干杯。
[剪]
$startDate = strtotime("$currentDay $currentMonthFull $currentYear");
$stTimeFormatted = strftime('%d/%m/%Y',$startDate);
$numPmnts = ($totalWeeks-$currentWeek);
for($i=0;$i<$numPmnts;$i++){
$ddates=array(
'sched_pay_id'=>$pmntID,
'due_date'=>date('m/d/y', strtotime('+'.$i.' week', $startDate)),
'is_paid'=>0,
);
$this->db->insert('sched_payments',$ddates);
}
Ello,
I am struggling with some date troubles here in PHP/MySql. I have a form that offers the recurrence of a payment yearly,quarterly,monthly,bi-weekly,or weekly and I need to be able to track when payments are made.
So for example, if something is added on Monday March 8th (that's the date it is being entered), recurring Weekly on Thursdays (the user would only see a dropdown offering days of the week -- as the recurrence is weekly), it would enter the 52 (weekly) due dates into the db (julian/whatever is easiest), and mark the first 9 of them paid (since those days are past); the rest entered but marked unpaid.
I have a table that would have each due_date entry, with a link to the payment detail, and a Boolean field paid/not paid.
So in the above example, the payments table would look something like:
id | pmnt_id | due_date | is_paid
1 | 0023 | 01/07/10 | 1
2 | 0023 | 01/14/10 | 1
3 | 0023 | 01/21/10 | 1
10 | 0023 | 03/25/10 | 0
11 | 0023 | 04/01/10 | 0
etc...
The problem is, well, everything. The calendaring system is so effed up, that there seems no real logical/straightforward way to do this. I've been racking my brain, searching goggle and php date manual all morning, and I'm just getting more confused.
Any ideas/suggestions/pointers would be greatly appreciated.
Cheers.
[snip]
$startDate = strtotime("$currentDay $currentMonthFull $currentYear");
$stTimeFormatted = strftime('%d/%m/%Y',$startDate);
$numPmnts = ($totalWeeks-$currentWeek);
for($i=0;$i<$numPmnts;$i++){
$ddates=array(
'sched_pay_id'=>$pmntID,
'due_date'=>date('m/d/y', strtotime('+'.$i.' week', $startDate)),
'is_paid'=>0,
);
$this->db->insert('sched_payments',$ddates);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能想查看 strtotime: http://php.net/manual/en/ function.strtotime.php,您可以对其进行循环,直到到达该时间段的末尾(在本例中为 52 周)。
You might want to look at strtotime: http://php.net/manual/en/function.strtotime.php, you could loop over that until you reach the end of the period (in this case 52 weeks).
新的 PHP 日期函数有一个 add 方法,您可以使用它生成所有这些日期。
The new PHP Date functions have an add method that you can use to generate all these dates.
这是重复天数的一个例子。
此函数返回一段时间内每周的重复天数。
示例:从 2010 年 5 月 6 日开始的 52 周内的所有星期四。
This an example of recurrence days.
This function return a recurrence day per week during a period.
Exemple: All Thurday starting from 06 May 2010 during 52 weeks.