The Problem
I am trying to convert a date-time field that is retrieved from a WSProxy
call previously. The date-time is provided to me in the format of YYYY-MM-DDTHH:mm:ss.sss
, trying to insert this value into a data extension where the field type is of type Date
will fail but will as expected successfully insert into Text
fields.
When I test and try to insert Date.now()
into a Date
data extension field, it works without issue. A Date.now()
value is also in milliseconds (epoch).
Because of this; I thought that I could simply use Date.parse(string)
which will convert a date-time string into its respective milliseconds' value (epoch). Unfortunately, this seems to fail.
My Sample Code
<script runat="server">
Platform.Load("Core", "1.1.1");
var myDE = DataExtension.Init("my_test_de");
var status = "complete"; // string
var start_time = Date.now(); // EPOCHmilliseconds
var complete_time = "2022-05-19T07:28:28.397" // string ISO
var date_complete_time = Date.parse(complete_time); // converts ISOstring to EPOCH
myDE.Rows.Add({Status: status, StartTime: start_time, CompleteTime: complete_time, CompleteTimeDate: date_complete_time});
</script>
The Question: How do I parse and insert an ISO Date-Time field retrieved in SSJS so that it will be accepted as input for a Date
Field in my Data Extension?
Thank you.