Solved
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):
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:
- 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?
- 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.