strptime() function in C fails to detect invalid dates. Ex: 2011-02-31 , 2011-04-31.
Is there any other function or workaround to this problem
strptime() function in C fails to detect invalid dates. Ex: 2011-02-31 , 2011-04-31. Is
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
mktimeto normalize your structure after usingstrptime.The example above will produce the output below:
If the strings before and after
mktimedo not match, then you know the input string was not a valid date.If you need to know which field was invalid, you can save a copy of the
ltmstructure before callingmktime. Then, you can examine if the day (tm_mday), month (tm_mon), or year (tm_year) was the one in the invalid format. Fortm_mon,0is January, and11is December. Fortm_year, it is the number of years since1900. Remember to account for leap year when validating the day of the month for February.