delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/26/06:49:43

Newsgroups: comp.os.msdos.djgpp,comp.lang.c,alt.sb.programmer,alt.msdos.programmer,comp.os.msdos.programmer
From: Bob Stout <rbs AT brokersys DOT com>
Subject: Re: Help with comparing dates
Message-ID: <E7MA51.2yn@twisto.eng.hou.compaq.com>
Sender: news AT twisto DOT eng DOT hou DOT compaq DOT com (System Administrator)
Mime-Version: 1.0
Organization: Compaq Computer Corp.
Date: Tue, 25 Mar 1997 20:55:49 GMT
References: <5gq9ar$efi AT ruby DOT ucc DOT nau DOT edu>
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).

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019