slj90 Posted June 3, 2016 Share Posted June 3, 2016 Hello,The user enters a 4 digit number as a date. Some examples:0101 = 1st January1902 = 19th Feb2412 = 24th DecemberIs there a way I can perform an if function to tell if the number isn't a date? For exampe if the user enters the number e.g 0001, 4112, 0199?I already make sure that it is a 4 digit number and not over 3112. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/301295-if-number-not-a-date/ Share on other sites More sharing options...
Jacques1 Posted June 3, 2016 Share Posted June 3, 2016 checkdate() Quote Link to comment https://forums.phpfreaks.com/topic/301295-if-number-not-a-date/#findComment-1533405 Share on other sites More sharing options...
Jacques1 Posted June 3, 2016 Share Posted June 3, 2016 By the way, it's generally best to not let users enter arbitrary digits in the first place. If there's any chance you can offer a proper datepicker or even just a dropdown menu, do it. It will save you a lot of trouble. 1 Quote Link to comment https://forums.phpfreaks.com/topic/301295-if-number-not-a-date/#findComment-1533406 Share on other sites More sharing options...
Adam Posted June 4, 2016 Share Posted June 4, 2016 Why over 3112? Strikes me as an odd number to limit it to. Quote Link to comment https://forums.phpfreaks.com/topic/301295-if-number-not-a-date/#findComment-1533407 Share on other sites More sharing options...
requinix Posted June 4, 2016 Share Posted June 4, 2016 It's pure coincidence that you can check for numbers > 3112 - if there was a 13th month with 30 days then >3013 wouldn't work. In principle you can only do comparisons like that if you have the data arranged in decreasing order of magnitude: MMDD. Go ahead and use 3112 but you still need checkdate(). By the way, what are you going to do about 2902? Quote Link to comment https://forums.phpfreaks.com/topic/301295-if-number-not-a-date/#findComment-1533409 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.