3

Is there an easy way to convert a date time value in format DD-MMM-YYYY HH:MM:SS.SSS to Progress DATETIME-TZ. For example, I am trying to store "15-Sep-2017 20:51:14.566" date in to Progress ABL variable whose datatype is datetime-tz with format "99/99/9999 HH:MM:SS.SSS+HH:MM".

I can get this working by splitting date, month, year, hours, minutes etc to individual variables and combining them using functions like DATE, DATETIME. But, I believe that there should be some good way of doing this. Thanks for your help.

Austin
  • 1,237
  • 1
  • 11
  • 22
  • I agree that there should be, but as of yet I've never found a useful date function in Progress. I always have to either do string manipulation or use the functions you have described. – Screwtape Jan 18 '18 at 13:15

2 Answers2

3

Don't worry about the Progress displayformat - as long as you convert your string to a datetime-tz you can always play around with display format later.

In this case I think you need to do it the "hard" way. Here's something to get you started.

DEFINE VARIABLE cDateString AS CHARACTER NO-UNDO.
DEFINE VARIABLE dtDate      AS DATETIME-TZ NO-UNDO.

FUNCTION convertDateString RETURNS DATETIME-TZ (INPUT pcString AS CHARACTER):

    DEFINE VARIABLE dtDateTz AS DATETIME-TZ NO-UNDO.
    DEFINE VARIABLE cDateTz  AS CHARACTER NO-UNDO.
    DEFINE VARIABLE iMonth AS INTEGER NO-UNDO.    

    CASE ENTRY(2, pcString, "-"):
        WHEN "Jan" THEN iMonth = 1.
        WHEN "Feb" THEN iMonth = 2.
        WHEN "Mar" THEN iMonth = 3.
        WHEN "Apr" THEN iMonth = 4.
        WHEN "May" THEN iMonth = 5.
        WHEN "Jun" THEN iMonth = 6.
        WHEN "Jul" THEN iMonth = 7.
        WHEN "Aug" THEN iMonth = 8.
        WHEN "Sep" THEN iMonth = 9.
        WHEN "Oct" THEN iMonth = 10.
        WHEN "Nov" THEN iMonth = 11.
        WHEN "Dec" THEN iMonth = 12.
    END CASE.

    IF iMonth = 0 THEN RETURN ?.

    ASSIGN 
        cDateTz = SUBSTRING(ENTRY(3, pcString, "-"), 1 ,4) + "-" + STRING(iMonth) + "-" + ENTRY(1, pcString, "-") + " " + ENTRY(2, pcString, " ").

    dtDateTz = DATETIME-TZ(cDateTz).

    RETURN dtDateTz.

END FUNCTION. 


cDateString = "15-Sep-2017 20:51:14.566".

dtDate = convertDateString(cDateString).

DISPLAY dtDate FORMAT "99/99/9999 HH:MM:SS.SSS+HH:MM".
Jensd
  • 7,886
  • 2
  • 28
  • 37
0

I know this is an old thread, but for the benefit of others who may find this: simple variable assignment will work.

DEFINE VARIABLE dt  AS DATETIME.
DEFINE VARIABLE dtz AS DATETIME-TZ /* FORMAT "..." */.

dt = NOW.
dtz = dt.
DISPLAY dt SKIP dtz.

[Edit] You can use the session variable SESSION:TIMEZONE to set the time zone used in this assignment. But there have been issues with that in older versions of Progress, and you may need to use the startup parameter -useSessionTZ. See the Progress KB article: Inconsistency assigning datetime-tz to datetime

Phil Freed
  • 98
  • 7