title: How to check if date is valid using mktime in C?
body: <p>I have a little problem with my code. I need to check if user's given date is valid or not. I want to check it using 2 rules:
  1. Date is valid date and found in a calendar (for example 29.2.2015 is invalid because there's only 28 days in February 2015) 2. Day and month can only be max 2 numbers (for example day 10 and 02 are valid but 010 and 002 are not). All help is appreciated!</p>
  
  <p>This is my code this far:</p>
  
  <pre><code>void dateValidator(const char *date1) {
  struct tm date = {0};
  
  int day1;
  int month1;
  int year1;
  
  int vday;
  int vmonth;
  int vyear;
  
  sscanf(date1, "%3d.%3d.%d",&amp;day1,&amp;month1,&amp;year1);
  /**How do I check that if sscanf reads more than 2 characters on month and day, date is 
  invalid?**/
  
  date.tm_year = year1 - 1900;
  date.tm_mon = month1 - 1;
  date.tm_mday = day1;
  date.tm_isdst = -1;
  
  vday = date.tm_mday;
  vmonth = date.tm_mon;
  vyear = date.tm_year;
  
  mktime(&amp;pvm);
  
  if ((vday != date.tm_mday) || (vmonth != date.tm_mon) || (vyear != date.tm_year)) {
          /**This doesnt seem to work**/
          printf("Invalid date");
  }
  }
  </code></pre>