Zoho Deluge: Convert Xero Date (Unix Timestamp) to Standard Date String

What?
So this is a super quick note that I'll probably remember anyway but just in case, I'm writing this article so I don't spend time researching it later.

Why?
I'm synchronizing Xero Invoices with Zoho CRM Invoices and noticed that Xero stores its dates in Unix Timestamps.

How?
We're going to filter out the unix seconds from the date provided by Xero then apply a toTime() function to it.
v_XeroTime="/Date(1586995200000+0000)/";
v_StartIndex = v_XeroTime.indexOf("(")+1;
v_EndIndex = v_XeroTime.indexOf("+", v_StartIndex);
v_UnixSeconds = v_XeroTime.subString(v_StartIndex, v_EndIndex);

info v_UnixSeconds.toLong().toTime();
// yields 15-Apr-2020 17:00:00

Chained
v_XeroTime="/Date(1586995200000+0000)/";
v_ZohoTime = v_XeroTime.subString(v_XeroTime.indexOf("(")+1, v_XeroTime.indexOf("+")).toLong().toTime();
// yields 15-Apr-2020 17:00:00

Using a regular expression
v_XeroTime="/Date(1586995200000+0000)/";
v_ZohoTime = v_XeroTime.replaceAll("[^0-9]", " ", false).trim().toList(" ").get(0).toLong().toTime();
// yields 15-Apr-2020 17:00:00

Additional
  • The reverse (date string to unix seconds) can be done using either of the following:
    v_MyDate = "2020-04-01 12:34:56";
    v_UnixSeconds = v_MyDate.toTime().toLong();
    info v_UnixSeconds;
    
    // or
    
    v_UnixSeconds = v_MyDate.unixEpoch();
    info v_UnixSeconds;
    
  • Error: Argument type mismatch -Found 'TEXT' but Expected 'Long' // Solution: Convert your string into a date.

Source(s)

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin - Valid till 8 May 2022 3QnhmaBX7LQSRsC9hh6Je9rGQKEGNQNfPb
© 2021 Joel Lipman .com. All Rights Reserved.