PHP simulates two date processing functions of SQLServer. It is very inconvenient to process dates in PHP, for example, to find the month of the difference between two dates? What should I do? File name: before using these two functions, date. inc. php3 is inconvenient to process the date or // In PHP, for example, to find the month of the difference between the two dates? What should I do? // File name: date. inc. php3 // before using these two functions, convert the date or date to the timestamp type. // For example: // $ today = mktime (0, 0, 0, date ("m"), date ("d"), date ("Y ")); /***** simulate the dateadd function in sqlserver ******* $ part Type: string value range: year, month, day, hour, min, sec: which part of the date to be added $ n type: value indicates the amount to be added, and which part to be added can be negative according to $ part $ datetime type: timestamp indicates the added base return type: timestamp *************************/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 sqlserver ******* $ part Type: string value range: year, month, day, hour, min, sec: which part of the date to be added $ date1, $ date2 type: timestamp indicates the two return types of dates to be compared:, $ date1, $ date2) {// $ diff = $ date2-$ date1; $ year1 = date ("Y", $ date1); $ year2 = date ("Y ", $ date2); $ month1 = date ("m", $ date2); $ month1 = date ("m", $ date1); $ day2 = date ("d ", $ date2); $ day1 = date ("d", $ date1); $ hour2 = date ("d", $ date2); $ hour1 = date ("d ", $ date1); $ min2 = date ("I", $ date2); $ min1 = date ("I", $ date1); $ sec2 = date ("s ", $ date2); $ sec1 = date ("s", $ date1); $ part = strtolower ($ part); $ ret = 0; switch ($ part) {case "year": $ ret = $ year2-$ year1; break; case "month": $ ret = ($ year2-$ year1) * 12 + $ mon2s-$ month1; break; case "day": $ ret = (mktime (, 0, $ mon2, $ day2, $ year2)-mktime, 0, $ month1, $ day1, $ year1)/(3600*24); break; case "hour": $ ret = (mktime ($ hour2, $ mon2, $ day2, $ year2)-mktime ($ hour1, 3600, $ month1, $ day1, $ year1)/; break; case "min ": $ ret = (mktime ($ hour2, $ min2, 0, $ mon2, $ day2, $ year2)-mktime ($ hour1, $ min1, 0, $ month1, $ day1, $ year1)/60; break; case "sec": $ ret = $ date2-$ date1; break; default: return $ ret; break;} return $ ret ;}}
Why? What should I do? // File name: date. inc. php3 // before using these two functions, you must first set the date or...