Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!uxc.cso.uiuc.edu!uxc.cso.uiuc.edu!m.cs.uiuc.edu!s.cs.uiuc.edu!mccaugh From: mccaugh@s.cs.uiuc.edu Newsgroups: comp.lang.c Subject: Re: Date-Routines for C/UNIX ? HELP Message-ID: <207600041@s.cs.uiuc.edu> Date: 12 Sep 89 06:02:00 GMT References: <298@nixsin.UUCP> Lines: 27 Nf-ID: #R:nixsin.UUCP:298:s.cs.uiuc.edu:207600041:000:1056 Nf-From: s.cs.uiuc.edu!mccaugh Sep 12 01:02:00 1989 I'm sorry if my code (in the first comment) is less than neat: I did test it out extensively so it at least works, but could be more efficient. In particular, the line assigning to variable lp_yrs should read: lp_yrs = (yyyy-1)/4 - 492; I tried modifying that line but it was already networked. Not sure what was meant by requesting 'previous day' or 'next day': were these requests for a new date or for the name of said day? In any event, just take the code I gave for day-of-week and add/subtract 86400 (= #(secs) per day) to value 'secs' to get a new duration in seconds, then proceed from there. The easiest part is checking date-validity, as the call to 'localtime()' returns info to check against the given date. Upon its return, we can first query if UNIX returns a date consistent with our own: /* check: dd == tp->tm_mday */ /* check: mm == tp->tm_mon */ /* check: yyyy == tp->tm_year */ and only then should the day-of-week be printed out. Again, hope this helps. Scott McCaughrin