这里的日期操作函数有时间的增加,计算出给出的日期是星期几,检查日期是否合法日期 时间比较函数,返回两个日期相差几秒、几分钟、几小时或几天.
- <?php
- function dateadd($date, $int, $unit = "d") {
-
-
- $datearr = explode("-", $date);
- $value[$unit] = $int;
-
-
-
- return date("y-m-d", mktime(0,0,0, $datearr[1] + $value['m'], $datearr[2] + $value['d'], $datearr[0] + $value['y']));
-
-
-
- }
-
- function getweekday($date) {
- $datearr = explode("-", $date);
- return date("w", mktime(0,0,0,$datearr[1],$datearr[2],$datearr[0]));
-
-
-
- }
- ?>
-
-
- <?
- function check_date($date) {
- $datearr = explode("-", $date);
- if (is_numeric($datearr[0]) && is_numeric($datearr[1]) && is_numeric($datearr[2])) {
- return checkdate($datearr[1],$datearr[2],$datearr[0]);
- }
- return false;
- }
- function check_time($time) {
-
-
-
- $timearr = explode(":", $time);
- if (is_numeric($timearr[0]) && is_numeric($timearr[1]) && is_numeric($timearr[2])) {
-
-
-
- if (($timearr[0] >= 0 && $timearr[0] <= 23) && ($timearr[1] >= 0 && $timearr[1] <= 59) && ($timearr[2] >= 0 && $timearr[2] <= 59))
-
-
-
- return true;
- else
- return false;
- }
- return false;
- }
-
-
- function datediff($date1, $date2, $unit = "") {
-
-
-
- switch ($unit) {
- case 's':
- $dividend = 1;
- break;
- case 'i':
- $dividend = 60;
-
- break;
- case 'h':
- $dividend = 3600;
- break;
- case 'd':
- $dividend = 86400;
- break;
- default:
- $dividend = 86400;
- }
- $time1 = strtotime($date1);
- $time2 = strtotime($date2);
- if ($time1 && $time2)
- return (float)($time1 - $time2) / $dividend;
- return false;
- }
- ?>
|