[prev in list] [next in list] [prev in thread] [next in thread]
List: aix-l
Subject: Re: Question re days between dates
From: Silvio Bandeira <silvio () DEI ! UNICAP ! BR>
Date: 2000-05-31 21:48:58
[Download RAW message or body]
See the attached files. The executable was built in AIX 4.2.1. The source is
available in "dates.c"
Chris Brett wrote:
> All,
>
> We have a need to obtain execute a piece of code which accepts two input
> parameters ( start date & end date ) in the format yyyymmdd and we want as
> output a string showing all the dates inbetween the two dates including the
> start and end dates ( same format) separated by white space.
>
> Regards
>
> Chris Brett
> Technical Systems Analyst
> Tel:02-6055-1121; Fax:02-6056-2169; e-mail:chris.brett@ap.effem.com
--
Silvio Bandeira
UNICAP - Dept. of Computer Science
["dates" (application/octet-stream)]
["dates.c" (text/plain)]
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
time_t t1=0,t2;
struct tm *ptm;
main(int argc, char *argv[])
{
if (argc != 3) {
fprintf(stderr, "Usage: %s first_date last_date\n", argv[0]);
exit(0);
}
ptm = localtime(&t1);
ptm->tm_hour = ptm->tm_min = ptm->tm_sec = 0;
ptm->tm_mday = atoi(&argv[1][6]);
argv[1][6] = '\0';
ptm->tm_mon = atoi(&argv[1][4]) - 1;
argv[1][4] = '\0';
ptm->tm_year = atoi(&argv[1][0]) - 1900;
t1 = mktime(ptm);
ptm->tm_mday = atoi(&argv[2][6]);
argv[2][6] = '\0';
ptm->tm_mon = atoi(&argv[2][4]) - 1;
argv[2][4] = '\0';
ptm->tm_year = atoi(&argv[2][0]) - 1900;
t2 = mktime(ptm);
for(;t1 <= t2; t1 += 86400) {
ptm = localtime(&t1);
printf("%04d%02d%02d ",(ptm->tm_year + 1900), (ptm->tm_mon + 1), ptm->tm
_mday);
}
exit(0);
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic