【问题标题】:Salary PHP Script [closed]工资 PHP 脚本 [关闭]
【发布时间】:2012-04-24 16:25:03
【问题描述】:

我正在寻找一个只显示不属于周末的工资日期的脚本。

例如,当月的第 1 天、第 15 天和最后一天可以是发薪日期,但如果日期是周末,则会显示下一个工作日。

这是迄今为止所做的......

<?php
date_default_timezone_set('UTC');

function firstDayOftheMonth($month){
    return date('j',mktime(1,1,1,$month,1,date('Y')));
}

function lastDayOfTheMonth($month){
    return date('j',mktime(-1,-1,-1,$month+1,1,date('Y')));
}

function daysInMonth($month){
    return cal_days_in_month($calendar, $month, date('Y'));
}

function getDay($day, $month){
    return date('l', mktime(0, 0, 0, $month, $day, date('Y')));
}

// Set year and month variables.
$months = 12;

echo "<strong>Month Name, 1st Expenses Day, 2nd Expenses Day, Salary Day</strong><br />";

// Loop through months
for($month=1; $month <= $months; $month++){
    echo "<strong>" . date('F', mktime(1, 1, 1, $month, 1, date('Y'))) . "</strong><br />";
    // Get No# days for each month of the year.
    $days = daysInMonth($month);
    // Loop through all days of the month.
    for($d=1; $d <= $days; $d++){
        // Get textual days
        $day = getDay($d, $month);
        if($d==firstDayOftheMonth($month) || $d==lastDayOfTheMonth($month) || $d==15){
            echo $d . ", " . $day . ", " . date('Y') . "<br />";
        }
    }

     echo "<hr />";
}

?>

非常感谢任何帮助。

提前致谢。

【问题讨论】:

  • 如果发薪日是周末,您通常不会在前一天收到薪水吗?

标签: php payment-processing


【解决方案1】:

您可以使用date('w') 来获取星期几作为数字。我想06 分别是星期日和星期六。

【讨论】:

    【解决方案2】:
    if(($i=date('w', $date))>=5) {
      $date = strtotime(date("Y-m-d", strtotime($date)) . "+ ".(7-$i).($==6 ? "day" : "days")); 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-07
      • 2014-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多