Working with dates in PHP is inconvenient, such as finding a month between two dates? What should we do?
File name: date.inc.php3
Before using these two functions, convert the date or datetime to the timestamp type.
Such as:
$today =mktime (0,0,0,date ("M"), Date ("D"), Date ("Y"));
/**** simulation of DATEADD functions in SQL Server *******
$part Type: string
Value range: year,month,day,hour,min,sec
Indicates: Which part of the date to increase
$n Type: Numeric
Indicate: How much to increase, according to $part decide which part to add
Can be a negative number
$datetime Type: Timestamp
Representation: 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;
}
http://www.bkjia.com/PHPjc/630924.html www.bkjia.com true http://www.bkjia.com/PHPjc/630924.html techarticle //working with dates in PHP is very inconvenient, such as finding a month between two dates? What should we do? File name: DATE.INC.PHP3//Before using these two functions, you must first set the date or ...