Hi @ryanmoravick ,
Regarding the DateTime format you've mentioned, "M/d/yyyy h:mm:ss a", I believe this is coming from SFMC, and I noticed that there's no time zone information included in the format. Generally, it's important to have the time zone information for accurate date-time conversions, and ideally, it should be like "M/d/yyyy h:mm:ss a z".
Since there's no time zone information in your data, the conversion becomes a bit more complex. Here are a couple of suggestions:
Option 1: Manually Set the Time Zone (e.g., EST)
You can assume that your date is in a specific time zone, for example, EST (Eastern Time). You can use the following code to set the time zone and convert to UTC:
format(zone_date_to_utc(zone_date_to_zone(date(DateTimeSend, "M/d/yyyy h:mm:ss a"), "America/New_York")), "yyyy-MM-dd'T'HH:mm:ss'Z'")
In this example:
"DateTimeSend" represents your input value, such as "1/2/2024 3:45:09 PM".
"America/New_York" is used to specify the Eastern Time Zone (EST/EDT).
Option 2: Append Time Zone Information Directly to the String
If the above solution doesn't work, you can hard-code the time zone information by appending it to your DateTimeSend value directly, like so:
format(zone_date_to_utc(date(concat(DateTimeSend + " PST"), "M/d/yyyy h:mm:ss a z")), "yyyy-MM-dd'T'HH:mm:ss'Z'")
In this case:
- The time zone
"PST" is appended to the original DateTimeSend value.
"M/d/yyyy h:mm:ss a z" is used as the format, where z represents the time zone.
Please give these approaches a try and let me know if you have any questions.
Best,
Parvesh