is there any function to check if a given date is valid or not? I don\'t want to write anything from scratch.
e.g. 32/10/2012 is not valid and 10/10/2010 is valid
If the format of the date is constant and you don't want to use boost, you can always use strptime
, defined in the ctime
header:
const char date1[] = "32/10/2012";
const char date2[] = "10/10/2012";
struct tm tm;
if (!strptime(date1, "%d/%m/%Y", &tm)) std::cout << "date1 isn't valid\n";
if (!strptime(date2, "%d/%m/%Y", &tm)) std::cout << "date2 isn't valid\n";