A one-liner is unlikely, but the strptime function can be used to parse your date format and the struct tm
argument can be queried for its tm_wday
member on systems that modify those fields automatically (e.g. some glibc implementations).
int get_weekday(char * str) {
struct tm tm;
memset((void *) &tm, 0, sizeof(tm));
if (strptime(str, "%d-%m-%Y", &tm) != NULL) {
time_t t = mktime(&tm);
if (t >= 0) {
return localtime(&t)->tm_wday; // Sunday=0, Monday=1, etc.
}
}
return -1;
}
Or you could encode these rules to do some arithmetic in a really long single line:
EDIT: note that this solution only works for dates after the UNIX epoch (1970-01-01T00:00:00Z).