Next Previous Contents

10. Time and date commands

You can use calc to do some operations on time and dates, such as calculating how many days are there between two dates.

Dates are entered in the format MM.DDYYYY, that is, the month is the integer part, the fractional part is the day and the year.

For example, the 26th of April of 1999 would be represented as 4.261999.

Times are entered in a similar format: HH.MMSS, that is, the hour is the integer part, and the fractional part contains the minutes and seconds. The hour is always in 24-hour format. So, 1:30:45pm would be represented as 13.3045.

You should not that whenever time is involved, the hours can be though as degrees, so the functions related to time are useful for dealing with angles in sexagesimal notation.

Here is a list of the commands related to time and dates:

10.1 The date command

This command puts the current date in the stack.

Example:

> date
[ 1]                  5.021999

10.2 The time command

This command puts the current time in the stack.

Example:

> time
[ 1]                   15.1941

10.3 The >hms command

This command converts time (or angles) in decimal format to HH.MMSS format.

Examples:

> 15.3030 >hms
[ 1]                  15.18108
> 5.4559 >hms
[ 2]                  15.18108
[ 1]                  5.272124

10.4 The hms> command

This command converts time (or angles) in HH.MMSS format to decimal format.

Examples:

> 15.18108 hms>
[ 1]                    15.303
> 5.272124 hms>
[ 2]                    15.303
[ 1]                    5.4559

10.5 The date+ command

This command adds an specified number of days (in level one) to a date (in level two).

Examples:

> 4.291999 15 date+
[ 1]                  5.141999
> 6.201999 60 date+
[ 2]                  5.141999
[ 1]                  8.191999

10.6 The ddays command

This command returns the number of days between two dates.

Examples:

> 4.291999 5.141999 ddays
[ 1]                        15
> 6.201999 8.191999 ddays
[ 2]                        15
[ 1]                        60

10.7 The hms+ command

This command adds time (or angles) in HH.MMSS format.

Examples:

> 22.59 .01 hms+
[ 1]                        23
> 7.3045 .4530 hms+
[ 2]                        23
[ 1]                    8.1615

10.8 The hms- command

This command subtracts time (or angles) in HH.MMSS format.

Examples:

> 23 22.59 hms-
[ 1]        0.0100000000000001
> 8.1615 7.3045 hms-
[ 2]        0.0100000000000001
[ 1]                     0.453

10.9 The dow command

This command returns the day of the week for a given date. The returned values are 0 for Sunday, 1 for Monday, etc...

Examples:

> date
[ 1]                  5.021999
> dow
[ 1]                         0
> 5.031999 dow
[ 2]                         0
[ 1]                         1

10.10 The dowstr command

This command returns a string with the three-letter abbreviation of the day of the week of a given date.

Examples:

> date
[ 1]                  5.021999
> dowstr
[ 1]                     "Sun"
> 5.031999 dowstr
[ 2]                     "Sun"
[ 1]                     "Mon"

10.11 The tstr command

This command takes as argument a date (in level two) and a time (in level one), and returns a string representing that time and date.

Example:

> date
[ 1]                  4.271999
> time
[ 2]                  4.271999
[ 1]                   15.3257
> tstr
[ 1] "Tue 04/27/1999  15:32:57...


Next Previous Contents