<?php
FileName: date.inc.php3
Before you use these two functions, you must first convert the date or datetime to the timestamp type.
Such as:
$today =mktime (0,0,0,date ("M"), Date ("D"), Date ("Y"));
/**** simulate the DATEADD function in SQL Server *******
$part Type: string
Value range: year,month,day,hour,min,sec
Which part of the date to increase
$n Type: Numeric value
said: To increase how much, according to $part decide which part to add
Can be a negative number
$datetime Type: Timestamp
Indicated: increased cardinality
return type: Timestamp
End **************/
function DateAdd ($part, $n, $datetime) {
$year =date ("Y", $datetime);
$month =date ("M", $datetime);
$day =date ("D", $datetime);
$hour =date ("H", $datetime);
$min =date ("i", $datetime);
$sec =date ("s", $datetime);
$part =strtolower ($part);
$ret = 0;
Switch ($part) {
Case "Year":
$year + + $n;
Break
Case "Month":
$month + + $n;
Break
Case ' Day ':
$day + + $n;
Break
Case "Hour":
$hour + + $n;
Break
Case "min":
$min + + $n;
Break
Case "SEC":
$sec + + $n;
Break
Default
return $ret;
Break
}
$ret =mktime ($hour, $min, $sec, $month, $day, $year);
return $ret;
}
/**** simulate the DATEDIFF function in SQL Server *******
$part Type: string
Value range: year,month,day,hour,min,sec
Which part of the date to increase
$date 1, $date 2 type: Timestamp
Indicates: two dates to compare
Return type: Numeric value
End * (*************/
function DateDiff ($part, $date 1, $date 2) {
$diff = $date 2-$date 1;
$year 1=date ("Y", $date 1);
$year 2=date ("Y", $date 2);
$month 2=date ("M", $date 2);
$month 1=date ("M", $date 1);
$day 2=date ("D", $date 2);
$day 1=date ("D", $date 1);
$hour 2=date ("D", $date 2);
$hour 1=date ("D", $date 1);
$min 2=date ("i", $date 2);
$min 1=date ("i", $date 1);
$sec 2=date ("s", $date 2);
$sec 1=date ("s", $date 1);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.