Written by

Question Brian Schoen · Jan 12, 2024

javascript Date() options

I am trying to pull out something similar to an HL7 date/time stamp in a custom zen page , in a javascript code section.

var d new Date();

(Fri Jan 12 2024 16:58:30 GMT-0500 (Eastern Standard Time)

but,
var year = d.getFullYear();

<Error>

d.<formatcmd>  doesn't seem to work.  (d.getmonth, etc.)

Is there and date formatting I can use inside a javascript routine?

Comments

Robert Cemper · Jan 12, 2024

check if the date object  var d=new Date();
is inside your routine or at least globally defined

0
Ambrogio De Lorenzo · Jan 15, 2024

Hello, it's not so clear, but if you try to convert date to HL7 you can use this:

d.toISOString().replace(/[-:]/g, '').split('.')[0]

This should generate a string with d in HL7 format.

0
Brian Schoen · Jan 18, 2024

Thanks all.  I ended up creating an ObjectScript Method that used $ZDATETIME and then called that method from within my Javascript routine..  (Which I should have thought of before I posted in the first place :)  )

0