Sudden error in 1 year old function

Let me refine the above. It happens like this:

  1. if you retrieve a field (declared as type “Date & Time” in Collection with getCurrentItem(), the field is retrieved in Preview Mode with data type “object” (correct) and in Publish Mode with data type “string”
  2. it happens 9 times out of 10 (so 1 out of 10 I get “object”, not string);

Proof

Code (partial):

let datEndDiscount = $w(‘#ddsPropsVIew’).getCurrentItem().ptValidThru;
console.log(“type datEndDiscount=” + typeof datEndDiscount );
console.log(“type ptValidThru=” + typeof $w(‘#ddsPropsVIew’).getCurrentItem().ptValidThru );

In Preview Mode:

In Publish Mode: