Extract the TIME portion of a DATE-TIME value

Posted by OctavioOlguin on 12-May-2015 18:17

Hi there!

I need to get the TIME part of a DATE-TIME field, and make STRING() to it, so I can show it in a readable form to the user?

All Replies

Posted by Matt Gilarde on 12-May-2015 18:25

I don't know if this is the easiest way but this knowledgebase article shows one method.

knowledgebase.progress.com/.../P75847

DEF VAR tsdate AS DATETIME.

/* Put a datetime value in tsdate variable */

/* equivalent to Assign tsdate = NOW. */

ASSIGN tsdate = DATETIME( TODAY, MTIME ).

/* display the time portion of the datetime variable with format  HH:MM:SS:NNN where NNN are the milliseconds */

DISPLAY  tsdate

         STRING( INTEGER( truncate( MTIME( tsdate ) / 1000, 0 ) ), "HH:MM:SS" ) + ":" + STRING( MTIME(tsdate) MODULO 1000, "999" ) FORMAT "x(16)".

Posted by OctavioOlguin on 12-May-2015 18:40

mmh.. I didn't wanted to do someting like:

STRING( INTERVAL (now, datetime(today, 0), "seconds"), "HH:MM:SS")

as I tought it was "un-elegant"

Posted by OctavioOlguin on 12-May-2015 18:43

Thanks!!!

Anyway..

Posted by Tony on 12-May-2015 20:29

Depending on your date/time format:

DEFINE VARIABLE dtDate AS DATETIME    NO-UNDO.

ASSIGN dtDate = NOW.

MESSAGE ENTRY(2, STRING(dtDate, "99/99/9999 HH:MM"), " ") SKIP

   ENTRY(2, STRING(dtDate), " ")

   VIEW-AS ALERT-BOX INFO BUTTONS OK.

Posted by Mark Davies on 12-May-2015 23:25

You can actually use MTIME...

Like:

MESSAGE STRING(INTEGER(MTIME(NOW) / 1000),"HH:MM:SS")

 VIEW-AS ALERT-BOX INFO BUTTONS OK.

This thread is closed