Creating a date

Basic types / Date and time

int year = 1945;
int month = 5;
int day = 9;

// tm_year counts from 1900, tm_mon from 0
struct tm tm = {.tm_year = year - 1900, .tm_mon = month - 1,
    .tm_mday = day, .tm_isdst = -1};
time_t victoryDate = mktime(&tm);
//mktime also fills in tm_wday and tm_yday

char sDate[32];
strftime(sDate, sizeof sDate, "%Y-%m-%d, %A", &tm);
//sDate is "1945-05-09, Wednesday"

bool beforeEpoch = victoryDate < 0;
//beforeEpoch is true: time_t counts seconds from 1970

printf("sDate is %s\n", sDate);
printf("beforeEpoch is %s\n", beforeEpoch ? "true" : "false");