Date and Time Functions

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.


Staff member
May 16, 2008
Migrated From JP Software Wiki

This article describes Date and Time functions, including parameterless functions that act as pseudo internal variables.

Pseudo internal variables

(Function definitions must be on a single line with no hard returns.)

12-hour format with am/pm

These consider noon to be 12:00 pm and midnight to be 00:00 am.

:  Returns current time in 12 hour format with am/pm, no seconds
:  Syntax: Echo %@now0ampm[]
now0ampm %@if[%_hour lt 13,%_hour,%@eval[%_hour-12]]:%_minute
 %@if[%_hour lt 12,a,p]m

:  Returns current time in 12 hour format with am/pm, with seconds
:  Syntax: Echo %@nowsecampm[]
nowsecampm %@if[%_hour lt 13,%_hour,%@eval[%_hour-12]]:%_minute:%_second
 %@if[%_hour lt 12,a,p]m

This shows the hour as 12 for times from midnight to 1 a.m.

:  Returns current time in 12 hour format with am/pm, no seconds
:  Syntax: Echo %@nowampm[]
nowampm %@if[%_hour lt 13,%@if[%_hour gt
 0,%_hour,12],%@eval[%_hour-12]]:%_minute %@if[%_hour lt
It's also possible to define these examples as actual variables in the environment (with or without a leading underscore depending on your preference) thus avoiding the need to call them as functions with no parameters. For example (all on one line):

set _nowampm=`%@if[%_hour lt 13,%@if[%_hour gt 0,%_hour,12],%@eval
[%_hour-12]]:%_minute %@if[%_hour lt 12,a,p]m`
May 29, 2008
Groton, CT
Function for getting MJD

The modified julian date (MJD) can be computed with this function:

function mjd=`%@eval[((%@makeage[%@if[%# eq 0,%_date %_time,%$]] + (%_tzo * 600000000) - 43199) \ 864000000000 ) - 94187]`

C:\work> echo %_date %_time %@mjd[] %@mjd[%_date %_time]
08-28-08 08:02:26 54706 54706

My %_tzo is 240 (Eastern Daylight Time), so tonight after midnight UTC:
C:\work> echo %@mjd[%_date 21:00]

Beginning of last century:
C:\work> echo %@mjd[1900-1-1]

Beginning of MJD:
C:\work> echo %@mjd[1858-11-17]

Dates earlier than 1858-11-17 will show negative, of course. Add 2,400,000.5 to get JD.

You can specify date or date,time but not time alone.
Uses current date and time if no parameter is given.

Dave C.
Function for getting MJD

dcantor wrote:
| Beginning of last century:
| C:\work> echo %@mjd[1900-1-1]
| 15020

In my calendar that's the last year of the 19th century... Only those for
whom the 1st century is only 99 years long (the years 1 ... 99 ) consider
the 100th year to be part of the 2nd century. Note that all numbers in dates
are ordinal numbers, e.g. today is the 12th day of the 11th month of the
2008th year.

Sorry, I just looked at the tips (in conjunction with reorganizing my
message rules).