Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to Assign a Datetime Field with a String Value?

BrandonPort
Giga Guru

HI All,

In my code I am receiving a JSON package and one of the values I receive is a date time in string format.

Example:

"PurchaseDateTime":"17\/08\/2022 16:50:00",

I am trying to assign this to a DateTime Field and my end result is always 2022-08-17 00:00:00

Assignment Code:

var bookingDateTime = data.Booking[i].PurchaseDateTime; //String Value From JSON example receipt 17\/08\/2022 11:30:00
bookingDateTime = bookingDateTime.replace(/\\/, ''); //lets get rid of the '\' from the string
gs.info("<BP> cpx_gsadmin_handler - processResponse: Purchase Date Time: " + bookingDateTime, "cpx_gsadmin_handler");
grBooking.purchase_date_time.setDisplayValue(bookingDateTime, "dd/MM/yyyy HH:mm:ss"); //TEST VALUE ASSIGNMENT 17\/08\/2022 11:30:00

the gs info output for the time formatted is as follows:

<BP> cpx_gsadmin_handler - processResponse: Purchase Date Time: 17/08/2022 16:50:00

The date is getting set correctly but not the time... 

Any assistance would be great!

Thanks

1 ACCEPTED SOLUTION

BrandonPort
Giga Guru

To resolve this issue I ended up splitting the datetime string and then applying them to a GladeDate and GlideTime separately. I was then able to manipulate the objects and merge them into a GlideDateTime object.  

View solution in original post

2 REPLIES 2

Yousaf
Giga Sage

Hi Brandon,

Check if this could help.

Need help with date/time field converting to string


Mark Correct or Helpful if it its helps.


***Mark Correct or Helpful if it helps.***

BrandonPort
Giga Guru

To resolve this issue I ended up splitting the datetime string and then applying them to a GladeDate and GlideTime separately. I was then able to manipulate the objects and merge them into a GlideDateTime object.