6 digit milli-second Date time value

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
MegumiSawada
Posts: 79
Joined: Tue Mar 22, 2016 1:45 pm
Location: Tokyo, Japan

6 digit milli-second Date time value

Post by MegumiSawada »

Hi All,

I'm trying to get the current date time (in ISO 8601 format).
#DateTime1.Value := #DATETIMEX.Now
will return value like 2023-07-13 04:47:40.747.

As you can see, milli-seconde will be 3 digit.
Is there anyway to get 6 digit milli-second value like 2023-07-13 04:47:40.747123?

I tried everything I can think of, but I still get only 3 digit...

Best Regards,
Megumi Sawada
René Houba
Posts: 220
Joined: Thu Nov 26, 2015 7:03 am

Re: 6 digit milli-second Date time value

Post by René Houba »

Hi Megumi,

I don't know if that is possible in VL.

I did some testing with the FractionalSeconds part in debug, but see that it always returns max 3 values:

Define Field(#FractionalSeconds) Type(*DEC) Length(30) Decimals(15)
#FractionalSeconds := #DATETIMEX.Now.FractionalSeconds
FractionalSeconds.PNG
FractionalSeconds.PNG (4.46 KiB) Viewed 9915 times
Kind regards,
René
User avatar
Dino
Posts: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: 6 digit milli-second Date time value

Post by Dino »

One alternative will be to use a widget to access a javascript function that can give you "microseconds". What you are looking is not milliseconds with 6 digit precision, but microseconds.

a good discussion is here... :
https://stackoverflow.com/questions/623 ... javascript
https://developer.mozilla.org/en-US/doc ... rmance/now

from a quick test with html/js, this lines can return the 6 digits microseconds you want:

Code: Select all

currentTime = performance.timeOrigin + performance.now();
alert(currentTime)
and using this page
https://dencode.com/en/date/iso8601

I can see that the time returned can be converted to iso8601 succesfully.... but....
iso8601 format only have 3 digits for millisecond, not microseconds.... so in that conversion you will loss the microseconds:
https://www.iso.org/iso-8601-date-and-time-format.html

then, you can create a widget like this, that can return the number in microseconds (I called it ROMicrosecond):
microsecond.jpg
microsecond.jpg (147.79 KiB) Viewed 9902 times
use this code for the implementation tab:

Code: Select all

function( PROTOTYPE, WIDGET )
{
  PROTOTYPE.onCreateInstance = function()  {  }

  // GetMicroseconds - Get Date and Time with microseconds from performance.now()
  // Type: Decimal
  PROTOTYPE.getGetMicroseconds = function()  {    return performance.timeOrigin + performance.now();  }
  PROTOTYPE.setGetMicroseconds = function( decValue )  {    this.m_GetMicroseconds = decValue;  }
  // Even though GetMicroseconds is read-only, setGetMicroseconds is still required for the default value

  return WIDGET.Completed;
}
and for example test this widget in a web page:

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_WEB) Theme(#SYS_THEME<MaterialDesignBlue>)

Define_Com Class(#ROMicrosecond) Name(#ROMicrosecond)

Evtroutine Handling(#Com_owner.Initialize)
#sys_web.Alert Caption(#ROMicrosecond.GetMicroseconds.AsString)
Endroutine

End_Com
MegumiSawada
Posts: 79
Joined: Tue Mar 22, 2016 1:45 pm
Location: Tokyo, Japan

Re: 6 digit milli-second Date time value

Post by MegumiSawada »

Hi René and Dino,

Thank you for your reply. These helps me a lot!

Best Regards,
Megumi Sawada
Post Reply