From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f678f,b221883f803a1c8a X-Google-Attributes: gidf678f,public From: tony@ermintrude.sunquest.com (Tony Jones) Subject: Re: Retrieving the day of week Date: 1996/04/09 Message-ID: <4kermh$2f7@odin.sunquest.com>#1/1 X-Deja-AN: 146627388 references: <31629fa4.0@news.planet.ch> organization: Sunquest Information Systems, Inc. newsgroups: comp.unix.osf.misc rossier@nagra-kudelski.ch wrote: : How can we retrieve the day of week according to a date which does not : contain explicitely the day (for example : 13 Jan 1996, 15:30) in C : -> The strptime function does not update the wday field in the : structure tm. >From strptime(3) (OSF/1 3.0) The strptime() function modifies only the fields in the tm structure that have corresponding conversion specifications in the format. Given this, I'd suggest using mktime/localtime to convert the struct tm to epoch time and back (maybe there is a better way anyone?) Two assumptions jump out here: 1) that you have zero'd your struct tm before calling strptime. 2) that your format to strptime fills in enough fields for the call to mktime to be meaningful. How portable this approach is, is open to debate. tony #include #include main() { struct tm tm; time_t t; bzero(&tm, sizeof(tm)); if (strptime("9 4 1999 10:01:59", "%d %m %Y %T", &tm) == NULL){ fprintf(stderr,"strptime error\n"); return 1; } printf("tm_wday=%d, asctime=%s\n", tm.tm_wday, asctime(&tm)); if ((t=mktime(&tm)) == (time_t)-1){ perror("mktime"); return 1; } printf("new asctime=%s\n", asctime(localtime(&t))); }