2 digit dates.

1 view
Skip to first unread message

Ed Clark

unread,
Jul 2, 2008, 3:04:28 PM7/2/08
to InterSy...@googlegroups.com
When you enter dates with 2 digit years in Cache, the default is to use a
window of 1900-1999, so ICONV('01/01/08','D') is interpreted as 1908 instead
of 2008. You can use the CENTURY.PIVOT verb in Cache to set the window, but
it only affects the current process.
There IS a way to set a system-wide default for the window. The subroutine
below demonstrated how to do this. You only need to run this once to set the
default.
This demonstrated calling it from mvbasic. You can also use object script
directly of course.

SUBROUTINE DEFAULT.CENTURY.PIVOT(DATE1,DATE2)
* call this from a program or run it from tcl as:
* ;CALL DEFAULT.CENTURY.PIVOT("01/01/1930","12/31/2029")
* The default window will be set, and activated for the current process.
* Other existing process will have to log off and back on before the
* default takes effect.
*******************************************************
DATEDIF=46385 ;* This is the difference between an mv date and a cos date.
StartDate=iconv(DATE1,'d')+DATEDIF
EndDate=iconv(DATE2,'d')+DATEDIF
x=$function("SetDefDateWindow^%DATE",StartDate,EndDate)
crt 'old default was ':oconv(x['^',1,1]-DATEDIF,'d4/'):' to
':oconv(x['^',2,1]-DATEDIF,'d4/')
x=$function("UseDefWindow^%DATE")
crt 'old process window was ':oconv(x['^',1,1]-DATEDIF,'d4/'):' to
':oconv(x['^',2,1]-DATEDIF,'d4/')
RETURN

Robert Nagle

unread,
Jul 2, 2008, 3:20:11 PM7/2/08
to InterSy...@googlegroups.com
Thanks Ed

RN

Benjamin Spead

unread,
Jul 2, 2008, 3:24:50 PM7/2/08
to InterSy...@googlegroups.com
Ed,
This looks like a great candidate for the first SUBROUTINE: articles in
the Community Articles section of the site:

http://groups.google.com/group/InterSystems-MV/web?hl=en

Would you be willing to write this up as an Article so that the code
isn't lost in the mailing list archives? If you have any questions as
to how to do this, please don't hesitate to ask.

Thanks!!

Ben

Greg Baryza

unread,
Jul 2, 2008, 3:58:17 PM7/2/08
to InterSy...@googlegroups.com
Ben:

Robert tasked Andreas with defining the spec to front this with a
class. Andreas has said he will have a draft ready by next week. I think
you should hold off a tad.

<G>

Michael Cohen

unread,
Mar 17, 2010, 3:17:23 PM3/17/10
to InterSy...@googlegroups.com
I recently provided a customer with a similar example and some notes.

Also, my results showed that this setting is lost on Caché restart, and so the call is required as part of system startup.

MultiValue CENTURY.PIVOT uses the existing Caché sliding 100-year window for 2-digit years, but just for the current process.

This can be set system-wide (at system startup or later) or for individual processes.

The code and doc is for Class %SYS.Date.SlidingWindow

To see the class doc, from Caché main doc page, click 'Class Reference' at the top, then on the left, 'System classes' should be checked; then part way down the left, click '%SYS', then 'Date', then 'SlidingWindow'.

There are many methods described. You can change the 100 year sliding window for 2-digit years system-wide, and/or for individual processes. If a single setting will work for all processes, you only need to set it system-wide one-time, as part of the system start process. This also affects tasks scheduled by the Caché Task Scheduler.

The Doc includes example:
Set status=##class(%SYS.Date.SlidingWindow).SetRelative(1,90,10)

This sets a relative window from 90 years ago to 10 years in the future

It also allows a call like:
Set status=##class(%SYS.Date.SlidingWindow).SetAbsolute(0,1930,2029)

This sets the window from 1/1/1930 to 12/31/2029

I changed the first arg above from 1 (process specific) to 0 (permanant, system-wide).
I did this from TCL, but you can use similar syntax for COS or MV objects calls.

* Here is what I did to test.
* First confirm that '09' is not 2009 by default.
MV:CENTURY.PIVOT
[150] Two digit years default to the years 1900 to 1999.
MV:;print oconv(15000,"d4")
24 JAN 2009
MV:;print iconv("24 JAN 2009","d")
15000
MV:;print iconv("24 JAN 09","d")
-21525
MV:
MV:[Set status=##class(%SYS.Date.SlidingWindow).SetRelative(0,90,10)
MV:[w status
1
MV:CENTURY.PIVOT
[151] Two digit years are set at the system level to the dates between01 Jan 1920 and 31 Dec 2019.


* open a new Terminal session and confirm the desired result ('09' IS 2009).
MV:;print iconv("24 JAN 09","d")
15000
MV:;print iconv("24 JAN 2009","d")
15000
MV:

Michael Cohen

unread,
Apr 27, 2010, 2:19:05 PM4/27/10
to InterSystems: MV Community
As a followup, note that Caché developer prodlog 78911 notes that
tasks scheduled via the System Management Portal Task Scheduler do not
honor the system sliding window setting in %ZSTART. If a Task
requires a two digit year sliding window, it must specify it itself.

--
You received this message because you are subscribed to the Google Groups "InterSystems: MV Community" group.
To post to this group, send email to Cac...@googlegroups.com
To unsubscribe from this group, send email to CacheMV-u...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/CacheMV?hl=en
Reply all
Reply to author
Forward
0 new messages