CustomObject datetime output off by 2 hours | Community
Skip to main content
New Participant
November 15, 2022
Solved

CustomObject datetime output off by 2 hours

  • November 15, 2022
  • 1 reply
  • 2459 views

OK, I've been reading through all of the material on these posts, but I seem to be missing one piece.  Context: we created a custom object for appointments, and one of the fields is appointment date, which is of type datetime.  In the REST API calls, we post the appointment date in the following format:

 

2022-12-03T12:00:00-08:00
 
In going to the test lead and looking at the custom objects, I see that the date is being stored correctly and adjusting it's display to match the timezone preference of my account in Marketo admin (PT but switching to other TZs in my account adjusts accordingly):


Cool, all good.  Now I've created a campaign triggered on an appointment add.  All good there.  I created a token for the date and time, and here's the time token definition:

#set( $dateOptions = { "formats" : { "userin" : "yyyy-MM-dd HH:mm:ss", "userout" : "hh:mm a z" }, "timezones" : { "userin" : "America/Los_Angeles", "userout" : "America/Los_Angeles" }, "locale" : $date.getLocale() } ) #set( $appointmentDatelike = $TriggerObject.appointmentDateTime ) #set( $appointmentDate = $convert.parseDate( $appointmentDatelike, $dateOptions.formats.userin, $dateOptions.locale, $date.getTimeZone().getTimeZone($dateOptions.timezones.userin) ) ) #set( $appointmentDate_formatted = $date.format( $dateOptions.formats.userout, $appointmentDate, $dateOptions.locale, $date.getTimeZone().getTimeZone($dateOptions.timezones.userout) ) ) ${appointmentDate_formatted}

Two questions:

  1. I was surprised that the userin format only worked with "yyyy-MM-dd HH:mm:ss" when it technically should be "yyyy-MM-dd'T'HH:mm:ssZ".  Why would this be the case, or am I mistaken?
  2. The output date that is being sent is coming back with 2:00 pm PT.  Given the example, I'm struggling to understand why this is the case.  Can someone provide some insight on this?

Thanks for any help you can provide.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

Two questions:

  1. I was surprised that the userin format only worked with "yyyy-MM-dd HH:mm:ss" when it technically should be "yyyy-MM-dd'T'HH:mm:ssZ".  Why would this be the case, or am I mistaken?
  2. The output date that is being sent is coming back with 2:00 pm PT.  Given the example, I'm struggling to understand why this is the case.  Can someone provide some insight on this?

  1. The stringified format exported in Velocity isn’t ISO 8601-valid, but it is Java-valid, so I wouldn’t necessarily say it technically should be ISO 8601 UTC since it doesn’t promise to be! (Though in a different, better world it would be.)
  2. The server timezone is Central, so you have to treat the incoming date as being local in Central.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
November 15, 2022

Two questions:

  1. I was surprised that the userin format only worked with "yyyy-MM-dd HH:mm:ss" when it technically should be "yyyy-MM-dd'T'HH:mm:ssZ".  Why would this be the case, or am I mistaken?
  2. The output date that is being sent is coming back with 2:00 pm PT.  Given the example, I'm struggling to understand why this is the case.  Can someone provide some insight on this?

  1. The stringified format exported in Velocity isn’t ISO 8601-valid, but it is Java-valid, so I wouldn’t necessarily say it technically should be ISO 8601 UTC since it doesn’t promise to be! (Though in a different, better world it would be.)
  2. The server timezone is Central, so you have to treat the incoming date as being local in Central.
jlinczakAuthor
New Participant
November 15, 2022

Thank you @sanfordwhiteman, that was the piece I was missing.  Do you mind telling me where you knew that?  I clearly missed the documentation from Marketo that notes this.  Appreciate your quick response - it helps me a ton!


Jon

Jon
SanfordWhiteman
New Participant
November 15, 2022

There’s scant official documentation, which is why most Marketo-Velocity devs read my blog posts. 🙂