1. Malek Taha
  2. PowerBuilder
  3. Monday, 19 December 2022 17:13 PM UTC

Hi

   I need to call an API that expect date time in this format. "2019-08-24T14:15:22Z"

Can you please direct me on how i can get this format from Powerbuilder 2021 powerscript.

 

Thank

Malek

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Monday, 19 December 2022 21:10 PM UTC
  2. PowerBuilder
  3. # Permalink

The following structure, external function declaration, and object function will convert a PB Datetime value from the user's local time zone to GMT/UTC/Zulu:

You need a PB structure that mimics the WinAPI SYSTEMTIME structure. I named it s_systemtime:

global type s_systemtime from structure
   integer  i_year
   integer  i_month
   integer  i_dayofweek
   integer  i_day
   integer  i_hour
   integer  i_minute
   integer  i_second
   integer  i_milliseconds
end type

You'll need an External Function Declaration for the Windows API function that will be called:

FUNCTION Boolean TzSpecificLocalTimeToSystemTime ( &
   Longptr          lpTimeZoneInformation, &
   s_systemtime     lpLocalTime, &
   REF s_systemtime lpUniversalTime &
   ) LIBRARY "kernel32.dll"

Here's an example of an object function that calls the Windows API function:

// Public Function of_Convert_To_UTC(Datetime adt_input) Returns Datetime

// Converts a Datetime value from the "local" timezone into GMT/UTC
// by utilizing a Windows API function.

Date     ld_temp
Time     lt_temp
Datetime ldt_utc
s_systemtime lstr_local, lstr_utc

// Extract date and time components of datetime argument value.
ld_temp = Date(adt_input)
lt_temp = Time(adt_input)

// Load the date and time components into the Windows API SYSTEMTIME structure.
lstr_local.i_Year         = Year(ld_temp)
lstr_local.i_Month        = Month(ld_temp)
lstr_local.i_Day          = Day(ld_temp)
lstr_local.i_Hour         = Hour(lt_temp)
lstr_local.i_Minute       = Minute(lt_temp)
lstr_local.i_Second       = Second(lt_temp)
lstr_local.i_Milliseconds = Integer(Right(String(lt_temp,"hh:mm:ss.fff"),3))

// Convert from local time to GMT/UTC. The zero first argument tells Windows
// to use the currently active time zone for the first SYSTEMTIME structure.
TzSpecificLocalTimeToSystemTime(0,lstr_local,lstr_utc)

// Construct the datetime value to be returned from the output SYSTEMTIME structure.
ld_temp = Date(lstr_utc.i_Year, &
               lstr_utc.i_Month, &
               lstr_utc.i_Day)
lt_temp = Time(lstr_utc.i_Hour, &
               lstr_utc.i_Minute, &
               lstr_utc.i_Second, &
               lstr_utc.i_Milliseconds)
ldt_utc = Datetime(ld_temp,lt_temp)

Return ldt_utc

Finally, here's an example that calls the object function, to test:

Datetime ldt_local, ldt_utc

ldt_local = Datetime(Today(),Now())

ldt_utc = of_Convert_To_UTC(ldt_local)

MessageBox("Convert to UTC","Current Local Date/Time:~t" + &
   String(ldt_local,"yyyy-mm-dd hh:mm:ss") + &
   "~r~n~r~nCurrent UTC Date/Time:~t" + &
   String(ldt_utc,"yyyy-mm-dd hh:mm:ss"))

As Roland suggests, you can format the date/time value as needed.

Good luck!

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 19 December 2022 17:19 PM UTC
  2. PowerBuilder
  3. # 1

Hi Malek;

   Unfortunately at this time, neither PowerBuilder or PowerServer support "time zone" date / time format. That excludes the XML & JSON processing as well.

Regards ... Chris 

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Monday, 19 December 2022 18:08 PM UTC
  2. PowerBuilder
  3. # 2

My Bcrypt example has a function of_CurrentUTC that returns a datetime containing the current UTC time. You can format a string from that easily.

https://www.topwizprogramming.com/freecode_bcrypt.html

 

Comment
There are no comments made yet.
Malek Taha Accepted Answer Pending Moderation
  1. Tuesday, 20 December 2022 11:38 AM UTC
  2. PowerBuilder
  3. # 3

Thank you very much John. This is super helpful appreciated.

Thank You 

Malek

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.