Script:
~addons/finance/finexec/datetime/datenumber.ijs
Contributor: William Szuch
Updated: 2022 5 26
Depend: nil
Definitions: loaded to locale base
Status: done
Script source:
datenember.ijs
This is an exercise in building long tacits for
todayno and todate.
Taken from the explicit definition in dates.ijs in stdlib
This script defines definitions that convert a date to a number
and a number to a date.
The J calendar starts from 1800 1 1 (Wed): day number = 0 eg: todate 0
gives 1800 1 1
also, 1 todate 0 gives 18000101
Use is made of the J addon: dates.ijs that is loaded to the z locale
as
part of the stdlib.ijs.
Monday is the first day of the week as per: ISO
8601.
Index: Monday = 0, Sunday = 6 (Days = 0 1 2 3 4 5 6)
calendar 2009
1 calendar 2009 (ISO 8601)
In the ISO 8601 calendar is a week that starts
on Monday.
1 YEAR = 365.2425 DAYS
Date format as a number: yyyy mm dd or
yyyymmdd
The preferred date formats:
yyyymmdd eg: 19970630
yyyy mm dd eg: 1997 6 30
Use ‘getdate’ for conversion of character dates
to format: yyyy mm dd.
An Excel date is a number displayed with a date
format.
It starts from 1900 1 1 with a well known leap year bug.
To convert from J day numbers (result of verb
‘todayno’ in dates.ijs),to
Excel day number subtract 36522 from the J day number.
Definitions to be completed.
numbertodate/numbertodatex
Definitions
datenumbertable (monad)
Form: explicit
depend: todate (stdlib: dates.ijs)
Table with 5 columns: yyyy mm dd daynumber yyyymmdd
1800 1 1 = 0 daynumber
Syntax
datenumbertable(N,N1)
N = start day number
N1 = number of days
Example
datenumbertable(0,2)
1800 1 1 0 18000101
1800 1 2 1 18000102
datenumbertable(80353,4)
2020 1 1 80353 20200101
2020 1 2 80354 20200102
2020 1 3 80355 20200103
2020 1 4 80356 20200104
datetonumber (monad)
Form: tacit
Depend: nil
Based on explixit todayno from dates.ijs (stdlib)
Convert a date to a day number.
Syntax
datetonumber(D)
D = table of dates with format YYYY MM DD
Example
datetonumber 2014 12 1
78496
datetonumber (1998 3 23,:2014 12 1)
72399 78496
datetonumber(1998 3 23,2014 12 1,2019 1 1,:2019 5 20)
72399 78496 79988 80127
datetonumberx (monad)
Form: tacit
Depend: nil
convert a date to a day number
Based on explicit todayno from dates.ijs (stdlib)
numbertodate (monad)
Form: tacit
Depend: nil
Convert a day number to a date
Based on explicit todate from dates.ijs (stdlib)
TO Do
Syntax
numbertodate(D)
D = day number
numbertodatex (monad)
Form: tacit
Depend: nil
Convert a day number to a date
Based on explicit todate from dates.ijs (stdlib)
To Do
Syntax
numbertodatex(D)
D = day number