如何在Mysql中查找给定年份的周开始日期和结束日期

时间:2011-12-02 13:51:22

标签: mysql

如何查找给定年份和周数的一周的开始和结束日期? 它用于在Hr模块项目的工作班次中插入每个员工的周日期,所以请帮助我

提前致谢, 婆

1 个答案:

答案 0 :(得分:0)

function Start_End_Date_of_a_week($week, $year){
    $time = strtotime("1 January $year", time());
    $day = date('w', $time);
    $time += ((7*$week)+1-$day)*24*3600;
    $dates[0] = date('Y-n-j', $time);
    $time += 6*24*3600;
    $dates[1] = date('Y-n-j', $time);
    return $dates;
}

$result = Start_End_Date_of_a_week(35,1998);
echo 'Starting date of the week: '. $result[0]."\n";
echo 'End date the week: '. $result[1];