home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.programmer:3821 comp.unix.questions:9238
- Newsgroups: comp.unix.programmer,comp.unix.questions
- Path: sparky!uunet!uunet.ca!geac!zooid!ross
- From: Ross Ridge <ross@zooid.guild.org>
- Subject: Re: Need (today's date + [1-7] days)
- Organization: ZOOiD BBS
- Date: Tue, 21 Jul 1992 05:27:06 GMT
- Message-ID: <1992Jul21.052706.11824@zooid.guild.org>
- Keywords: date
- References: <1992Jul16.145836.15586@avalon.nwc.navy.mil>
- Lines: 41
-
- dejesus@archimedes.nwc.navy.mil (Francisco X DeJesus) writes:
- >I realize that date/time-related questions are common here, so no flames
- >if this has been asked before...
- >
- >If I can get today's date in a shell script or C program, how can I find
- >out the dates of the next week? For example, if I know today is
- >"Wed Dec 30 1992", how can I have the program now that the next seven days
- >are going to be "Thu Dec 31 1992", "Fri Jan 1 1993", etc (taking the
- >case in which both month and year could change).
-
- In C something like:
-
- int
- main(argc, argv)
- int argc;
- char **argv; {
- long now, time(), atol();
-
- now = time((long *)0);
- if (argc == 2) {
- now += atol(argv[1]) * 60L * 60L * 24L;
- }
-
- puts(ctime(&now));
-
- return 0;
- }
-
- If you call this programme "foo", then "foo 3" will print out what
- the time and date will be three days from now in the same format
- as the date command. The key thing here is that Unix time is
- kept as the number of seconds since midnight Jan 1 1970 GMT, and
- so it's easy to do arithmetic like adding a day.
-
- Ross Ridge
-
- --
- Ross Ridge - The Great HTMU l/ //
- [OO][oo]
- ross@zooid.guild.org /()\/()/
- uunet.ca!zooid!ross db //
-