C-Kermit 7.0 Case Study #17

[ Previous ] [ Next ] [ Index ] [ C-Kermit Home ] [ Kermit Home ]

Article: 11087 of comp.protocols.kermit.misc
From: fdc@watsun.cc.columbia.edu (Frank da Cruz)
Newsgroups: comp.protocols.kermit.misc
Subject: Case Study #17: Fun with Dates and Times
Date:27 Jan 2000 23:52:05 GMT
Organization: Columbia University

C-Kermit 7.0 (and Kermit 95 1.1.18 when it comes out) let you use dates and times as "native" data types in your commands and scripts. We spoke about this a little bit in the "How Do I Delete Files More Than a Week Old?" example but that just skimmed the surface.

I won't bother listing the rules for writing dates and times; they are spelled out in Section 1.6 of the C-Kermit 7.0 Update Notes. Assuming you know how to write dates and times, what can you do with them?

You have already seen how they can be used as file selectors. For example, to send all files that were created in December 1999, you could:

  SEND /NOT-BEFORE:1999-12-01 /BEFORE:2000-01-01 *.*

/NOT-BEFORE is almost the same as /AFTER, except /NOT-BEFORE includes the given date-time (in this case the implied time of 00:00:00 on December 1), whereas /AFTER excludes it. A fine point indeed! (Of course there is also a /NOT-AFTER switch, which has the same relationship to /BEFORE.)

To illustrate dates with explicit times, here is a command to send log files created after noon on the 27th day of January of this year:

  SEND /AFTER:{2000-01-27 12:00:00} *.log

A date-time is a single field (or "word") in Kermit syntax, so must be enclosed in braces if it contains any spaces, as shown above (of course other variations are possible).

To experiment with date-time formats, use C-Kermit's new DATE command. If you type "date" by itself, it prints the current date and time. If you follow it by something, C-Kermit tries to interpret the "something" as a date and/or time and prints the result (or an error message).

Perhaps the most interesting aspect of C-Kermit's new date-time support is the ability to do date and time arithmetic. This works in two ways. First, by using the built-in relative date syntax: YESTERDAY, TOMORROW, +3DAYS, -6WEEKS, +12YEARS, etc, for example:


All the built-in symbolic dates are relative to "today", the current date.

You can also perform explicit calculations, such as obtaining a date that is a given number of days after a given date, or finding out the day of the week for a given date.

All of C-Kermit's date calculations are based on the Modified Julian Date (MJD), which is the number of days since 17 November 1858. For dates prior to 17 Nov 1858, the MJD is negative. MJDs are scalar counting numbers (unlike the "yyyyddd" format, often but improperly called the Julian date), so you can do arithmetic on them. For example, if today's MJD is 51570, then 100 days from today, the MJD will be 51570 + 100 = 51670.

MJDs have some other interesting properties too: