Newsgroups: comp.os.msdos.djgpp,comp.lang.c,alt.sb.programmer,alt.msdos.programmer,comp.os.msdos.programmer From: Bob Stout Subject: Re: Help with comparing dates Message-ID: Sender: news AT twisto DOT eng DOT hou DOT compaq DOT com (System Administrator) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Compaq Computer Corp. Date: Tue, 25 Mar 1997 20:55:49 GMT References: <5gq9ar$efi AT ruby DOT ucc DOT nau DOT edu> Content-Transfer-Encoding: 7bit Lines: 37 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Everything you need is in SNIPPETS. The file PARSDATE.C contains the following function (the data types are declared in other headers)... /* ** parse_date() - Parse a date string into its components ** ** Arguments: 1 - String to parse ** 2 - Address of year storage ** 3 - Address of month storage ** 4 - Address of day storage ** 5 - Syntax to use ** ** Returns: 0 For success, non-zero for range errors ** ** Notes: The following syntaxes are supported: ** ** Date ordering: USA (month, day, year), ** ISO (year, month, day) ** EUROPE (day, month, year) ** Delimiters: Spaces, commas, dashes, periods, slashes. (" ,-./") ** Years: 2-digit years assumed to be between 1970 and 2069 ** 4-digit years required otherwise */ Boolean_T parse_date(const char *str, unsigned *year, unsigned *month, unsigned *day, Syntax_T syntax) This will parse your date string reliably. You then feed the dates into the ymd_to_scalar() function in SCALDATE.C, which converts them to scalar values (if you want true Julian day numbers, use ymd_to_jdnl() in JDN_L.C instead). The resulting long int scalar values can then be compared, days added or subtracted, and the resulting scalar values converted back to dates using the scalar_to_ymd() function in SCALDATE.C (or jdnl_to_ymd() in JDN_L.C).