Check whether the date is valid
Check whether the date is valid
- Function check_date ($ date) {// check whether the date is valid
- $ DateArr = explode ("-", $ date );
- If (is_numeric ($ dateArr [0]) & is_numeric ($ dateArr [1]) & is_numeric ($ dateArr [2]) {// open source OSPhP. COM. CN
- Return checkdate ($ dateArr [1], $ dateArr [2], $ dateArr [0]);
- }
- Return false;
- }
- Function check_time ($ time) {// check whether the time is valid
- // OSPHP. COM. Cn open source
- $ TimeArr = explode (":", $ time );
- If (is_numeric ($ timeArr [0]) & is_numeric ($ timeArr [1]) & is_numeric ($ timeArr [2]) {
- // Open source code OSPHP. COM. Cn
- If ($ timeArr [0]> = 0 & $ timeArr [0] <= 23) & ($ timeArr [1]> = 0 & $ timeArr [1] <= 59) & ($ timeArr [2]> = 0 & $ timeArr [2] <= 59 ))
- // PHP open source code
- Return true;
- Else
- Return false;
- }
- Return false;
- }
- Function DateDiff ($ date1, $ date2, $ unit = "") {// Time comparison function, returns the seconds, minutes, hours, or days of difference between two dates
- Switch ($ unit ){
- Case's ':
- $ Pidend = 1;
- Break;
- Case 'I ':
- $ Pidend = 60;
- // OSPHP. COM. CN
- Break;
- Case 'H ':
- $ Pidend = 3600;
- Break;
- Case 'D ':
- $ Pidend = 86400;
- Break;
- Default:
- $ Pidend = 86400;
- }
- $ Time1 = strtotime ($ date1 );
- $ Time2 = strtotime ($ date2 );
- If ($ time1 & $ time2) // OSPHP.com. CN
- Return (float) ($ time1-$ time2)/$ pidend;
- Return false;
- }
- ?>
|