How can you extract the time from a DATETIME field?

Posted by rbf on 05-Jul-2011 03:02

You would think this to be a simple task in the ABL, but it isn't.

I have a DATETIME field that contains the DATE and TIME of an appointment.

I have a Browse (Grid actually) that shows all appointments on a certain day.

Since all of these appointments are on the same day and there are many fields to show, the requirement is to show only the time part.

Apparently the DATETIME display format does not allow for this.

So I thought extracting this information to a CHARACTER field for display purposes like this but

I cannot get that to work either. Any suggestions?

All Replies

Posted by jmls on 05-Jul-2011 03:56

not pretty, but works ok ...

def var dt as datetime no-undo.

dt = now.

message string(interval(dt,datetime(date(dt)),"seconds"),"HH:MM:SS")

Posted by rohit.ramak on 05-Jul-2011 05:08

MESSAGE SUBSTRING(STRING(NOW),11,9)

        VIEW-AS ALERT-BOX INFO BUTTONS OK.

Posted by rbf on 05-Jul-2011 09:35

rohit.ramak wrote:

MESSAGE SUBSTRING(STRING(NOW),11,9)

        VIEW-AS ALERT-BOX INFO BUTTONS OK.

Works for me!

Beautiful in it's simplicity.

Thanks!

Posted by jmls on 05-Jul-2011 10:46

pffft. Who needs simples ?

Posted by Håvard Danielsen on 06-Jul-2011 10:06

Your example is future proof.  The substring would be incorrect with a 5 digit year...

This thread is closed