www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/25/10:27:32

From: Alicia Carla Longstreet <carla AT ici DOT net>
Newsgroups: comp.os.msdos.djgpp,comp.lang.c,alt.sb.programmer,alt.msdos.programmer,comp.os.msdos.programmer
Subject: Re: Help with comparing dates
Date: Mon, 24 Mar 1997 11:24:36 -0500
Organization: The Computer Solution
Lines: 73
Message-ID: <3336AAC4.4B4F@ici.net>
References: <5gq9ar$efi AT ruby DOT ucc DOT nau DOT edu> <5gtf0l$lk3$1 AT opera DOT iinet DOT net DOT au>
Reply-To: carla AT ici DOT net
NNTP-Posting-Host: d-ma-fallriver-19.ici.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Jamie Ingram wrote:
> 
> mdr6 AT dana DOT ucc DOT nau DOT edu (Michael Dylan Ryan) spoke unto the masses,
> thusly:
> 
> :-) Can someone help me with a function to compare two dates.  I want to write
> :-) a function that will take a date string char *d = "03/01/97" and two other
> :-) date strings, start and end, and check to see if d is in between them.
> 
> :-) I have been working with dates for a while and can never get a function to
> :-) compare accurately 100% of the time.  Any help appreciated.
> 
> :-) --
> :-) Michael D. Ryan [Dark Brotherhood Software]
> :-) Email: dbrotherhood AT geocities DOT com
> :-)        mdr6 AT dana DOT ucc DOT nau DOT edu
> :-)        TheShogun AT aol DOT com
> :-) Programming Page:  http://www.geocities.com/SiliconValley/Pines/5301/
> :-) --
> G'Day Michael,
> Why not reorganise the date so that it is YY/MM/DD? Then do a string
> compare. The string compare will return an error level which you can
> use to determine if the date falls between the other two. See below.
> 
> <Disclaimer: While this may not be the best example, it does
> illustrate my point. I will happily accept any constructive
> criticism.>

Just one, please use 4 digits for the year (CCYYMMDD).

> Jamie Ingram
> jamiei AT potato DOT wa DOT gov DOT au
> 
> #include <stdio.h>
> #include <string.h>
> 
> void swap(char &a, char &b)
> {char temp;
>  temp = b;
>  b = a;
>  a = temp;
>  return ;}
> 
> int main(void)
> {
> char date[9],startDate[9], finishDate[9];
> char temp;
> puts("\nEnter a date dd/mm/yy\n");
> gets(date);
> swap(date[0], date[6]);
> swap(date[1], date[7]);
> puts("\nEnter start date dd/mm/yy\n");
> gets(startDate);
> swap(startDate[0], startDate[6]);
> swap(startDate[1], startDate[7]);
> puts("Enter finish date dd/mm/yy\n");
> gets(finishDate);
> swap(finishDate[0], finishDate[6]);
> swap(finishDate[1], finishDate[7]);
> 
> if ((strcmp(startDate,date)<= 0)&& (strcmp(date,finishDate)<= 0))
>  printf("\nThe date is within the range of the other two dates.\n");
> 
> return 0;}

-- 
********************************************
* Alicia Carla Longstreet     carla AT ici DOT net
********************************************
On France:
I came, I saw, I conquered - A man.
I came, I saw, I shopped   - A woman.
                        Who is smarter.

- Raw text -


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