根据当前日期在 PHP 中创建重复日期,并使用布尔值表示完成或未完成

发布于 2024-08-21 15:22:12 字数 1125 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

愛放△進行李 2024-08-28 15:22:12

您可能想查看 strtotime: http://php.net/manual/en/ function.strtotime.php,您可以对其进行循环,直到到达该时间段的末尾(在本例中为 52 周)。

for i = 1, i <= 52, i++
    insert date(mm / dd / YY, strtotime(+ i week));
/for

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).

for i = 1, i <= 52, i++
    insert date(mm / dd / YY, strtotime(+ i week));
/for
鲸落 2024-08-28 15:22:12

新的 PHP 日期函数有一个 add 方法,您可以使用它生成所有这些日期。

$startDate = new DateTime();

// "Period of 1 Week
$interval = new DateInterval("P1W");

// Will cycle from 1st week's due date to the end of payment cycle
for($i = 1; $i <= 52; $i++) {
    $dueDate = $date->add($interval);
    $date = $dueDate;
}

The new PHP Date functions have an add method that you can use to generate all these dates.

$startDate = new DateTime();

// "Period of 1 Week
$interval = new DateInterval("P1W");

// Will cycle from 1st week's due date to the end of payment cycle
for($i = 1; $i <= 52; $i++) {
    $dueDate = $date->add($interval);
    $date = $dueDate;
}
瑾夏年华 2024-08-28 15:22:12

这是重复天数的一个例子。

此函数返回一段时间内每周的重复天数。
示例:从 2010 年 5 月 6 日开始的 52 周内的所有星期四。

<?php 
//function
function nextWeeksDay($date_begin,$nbrweek)
{
$nextweek=array();
for($i = 1; $i <= $nbrweek; $i++)  { // 52 week in one year of course
$nextweek[$i]=date('D d M Y', strtotime('+'.$i.' week',$date_begin));
}
return $nextweek;
}
/// end function 
/// example of a select date 
// var
$date_begin = strtotime('06-05-2010'); //D Day Month Year  - like function format.
$nbrweek=52;
// call function
$result=nextWeeksDay($date_begin,$nbrweek);
// Preview 
for($i = 1; $i <= $nbrweek; $i++)  {
echo '<br> - '.$result[$i];
}
?>

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.

<?php 
//function
function nextWeeksDay($date_begin,$nbrweek)
{
$nextweek=array();
for($i = 1; $i <= $nbrweek; $i++)  { // 52 week in one year of course
$nextweek[$i]=date('D d M Y', strtotime('+'.$i.' week',$date_begin));
}
return $nextweek;
}
/// end function 
/// example of a select date 
// var
$date_begin = strtotime('06-05-2010'); //D Day Month Year  - like function format.
$nbrweek=52;
// call function
$result=nextWeeksDay($date_begin,$nbrweek);
// Preview 
for($i = 1; $i <= $nbrweek; $i++)  {
echo '<br> - '.$result[$i];
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文