SOLVED

Re: CustomObject datetime output off by 2 hours

Go to solution
jlinczak
Level 2

CustomObject datetime output off by 2 hours

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):

jlinczak_0-1668536867663.png


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.

Jon
Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: CustomObject datetime output off by 2 hours


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.

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: CustomObject datetime output off by 2 hours


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.
jlinczak
Level 2

Re: CustomObject datetime output off by 2 hours

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
Level 10 - Community Moderator

Re: CustomObject datetime output off by 2 hours

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

jlinczak
Level 2

Re: CustomObject datetime output off by 2 hours

Hahaha - just discovered your blog.  Thank you for the sheer volume of time you must put into this.  Appreciate it!

Jon