Parse the input into elements of a struct tm
, then convert into time_t
#include <stdlib.h>
#include <time.h>
char input[] = "2003-06-16";
struct tm temp = {0};
temp.tm_mday = strtol(input + 8, NULL, 10); // needs error checking
temp.tm_mon = strtol(input + 5, NULL, 10) - 1; // needs error checking
temp.tm_year = strtol(input, NULL, 10) - 1900; // needs error checking
time_t unix_seconds = mktime(&temp);
Apparently you just need a temporary holding space for the date. So keep it in the same format as input and output: keep it as a string.