PHP simulation of two date processing functions for SQL Server

xiaoxiao2021-03-06  58

Treatment date is very inconvenient in PHP, such as the month between the two dates? what can we do about it? // File Name: Date.inc.php3 // Before using these two functions, you must first convert the date or date time to the TimeStamp type.

//, such as: // $ TODAY = MKTIME (0, 0, 0, Date ("M"), Date ("D"), Date ("y")); / **** Analog DateAdd function in SQL Server ******* $ Part Type: String Value Range: Year, Month, Day, Hour, min, sec Repository: Which part of the date to add $ n: Value means: How much should be added, according to $ part Decide which portion can be negative $ datetime type: TimeStamp Represents: Added Base 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;} / **** Datediff function in SQL Server ******* $ part type: String Value Range: Year, Month, Day, Hour, min, sec, $ DATE1, $ DATE2 Type: TimeStamp Representation: Numeric ***** ******* ** End * (************ / Function Datediff ($ Part, $ DATE11, $ DATE2) {/ $ DIFF = $ DATE2- $ DATE1; $ Year1 = Date ("Y ", $ DATE1); $ YEAR2 = Date (" y ", $ date2; $ month2 =

转载请注明原文地址:https://www.9cbs.com/read-113589.html

New Post(0)