ISO-DATE value to DATETIME

Posted by OctavioOlguin on 21-Sep-2015 13:51

Greetings.

Is there some "elegant", as in "direct way", to pass a value like:

"2015-09-21T13:50:00" to a DATETIME field?

The value I got came form a webservice, and want to store on datetime field... and for now I came to very complex SUBSTRINGing of the value...

just want to keep good readability...

TIA

All Replies

Posted by tbergman on 21-Sep-2015 14:09

If you're on Windows and any reasonably current version of Progress try

def var MyDateTime as DateTime.

MyDateTime = System.DateTime:Parse("2015-09-21T13:50:00").

MESSAGE MyDateTime

VIEW-AS ALERT-BOX.

Posted by OctavioOlguin on 21-Sep-2015 14:29

There you go!!

That was I mean.   Thanks.

This

DEFINE VARIABLE foo      AS date NO-UNDO.

DEFINE VARIABLE bar      AS integer   NO-UNDO.

DEFINE VARIABLE cHora    AS CHARACTER NO-UNDO.

DEFINE VARIABLE base     AS CHARACTER NO-UNDO INITIAL "2015-09-21T14:22:34" format "X(19)".

assign

    cHora = entry(2, base, "T")

    bar = (INTEGeR(entry(1, cHora, ":")) * 60000 * 60) + (INTEGeR(entry(2, cHora, ":")) * 60000)   +  INTEGeR(entry(3, cHora, ":")) * 1000.

    foo = date(integer(entry(2, base, "-")), integer(substring(base, 9, 2)), integer(entry(1, base, "-"))).

DISPLAY base

   datetime(foo, bar).

versus

def var MyDateTime as DateTime.

MyDateTime = System.DateTime:Parse("2015-09-21T14:22:34").

MESSAGE MyDateTime

VIEW-AS ALERT-BOX.

Thanks!!!.

Posted by tbergman on 21-Sep-2015 14:39

It's actually not that hard to do in pure Progress. I prefer the .net way and the DateTime parse method is incredibly powerful for converting a wide variety of date strings.

But here's a pure Progress way.

def var MyDateTime as dateTime.

def var oldDateFormat as char.

oldDateFormat = session:date-format.

session:date-format = "YMD".

MyDateTime = DateTime(REPLACE("2015-09-21T14:22:34","T"," ")).

session:date-format = oldDateFormat.

MESSAGE MyDateTime

VIEW-AS ALERT-BOX.

This thread is closed