Compare date and determine whether the date is valid
$ SmallDate returned> 0 * $ bigDate <$ smallDate returned <0 * $ bigDate = $ smallDate returned = 0 ** @ param $ bigDate * @ param $ smallDate ** @ returns */ public static function dateCmp ($ bigDate, $ smallDate) {if (! Self: isDate ($ bigDate) |! Self: isDate ($ smallDate) {throw new Exception ('Parameter is not a valid date');} return strcmp ($ bigDate, $ smallDate );} public static function isDate ($ dateTime, $ checkTime = false) {$ strArray = explode ('', $ dateTime); $ date = $ strArray [0]; $ time = $ strArray [1]; // if (! $ Date |! $ Time) {return false;} $ dateArray = explode ('-', $ date); $ year = $ dateArray [0]; $ month = $ dateArray [1]; $ day = $ dateArray [2]; // year from 1 to 9999 if (! Self: _ checkLimit ($ year, 1, 9999) {return false;} if (! Self: _ checkLimit ($ month, 1, 12) {return false;} if (! Self: _ checkLimit ($ day, 1, 31) {return false;} if ($ checkTime) {$ timeArray = explode (':', $ time ); $ hour = $ timeArray [0]; $ minute = $ timeArray [1]; $ second = $ timeArray [2]; if (! Self: _ checkLimit ($ hour, 0, 24) {return false;} if (! Self: _ checkLimit ($ minute, 0, 60) {return false;} if (! Self: _ checkLimit ($ second, 0, 60) {return false ;}} return true ;} /*** check whether the string is within the start to interval ** @ param $ str * @ param $ start * @ param $ to ** @ returns */private static function _ checkLimit ($ str, $ start, $ to) {if ($ str <$ start | $ str >$ to) {return false;} return true ;}}