Skip to main content
Solved

Take away time stamp from ISO date

  • June 7, 2020
  • 2 replies
  • 83 views

Kim_Trager1
Forum|alt.badge.img+23

I’m trying to format a bunch of date ranges to be used in WORKDAY().
I created a script that collects these dates from a base and have them converted to iso-dates.
However all my dates has a trailing time stamp of T00:00:00.000Z.
Wondering if there is a quick way to omit of the time stamp so it’s only YYYY-MM-DD?

Best answer by Bill_French

Well, there are as many ways to do this as there are to compute your personal tax liability, but… I’m lazy so when dealing with predictable strings - like an ISO date - I just do this:

Given this:

let isoDate = "2016-05-24T15:31:48.335Z";

I would simply:

let dateOnly = isoDate.split("T")[0];

Javascript experts would probably spit on my grave for suggesting this. But in a sanitized environment like Script Blocks, I’m not actually sure what level of date formatting support exists.

2 replies

Forum|alt.badge.img+19
  • Inspiring
  • 3263 replies
  • Answer
  • June 7, 2020

Well, there are as many ways to do this as there are to compute your personal tax liability, but… I’m lazy so when dealing with predictable strings - like an ISO date - I just do this:

Given this:

let isoDate = "2016-05-24T15:31:48.335Z";

I would simply:

let dateOnly = isoDate.split("T")[0];

Javascript experts would probably spit on my grave for suggesting this. But in a sanitized environment like Script Blocks, I’m not actually sure what level of date formatting support exists.


Kim_Trager1
Forum|alt.badge.img+23
  • Author
  • Brainy
  • 168 replies
  • June 8, 2020

Well, there are as many ways to do this as there are to compute your personal tax liability, but… I’m lazy so when dealing with predictable strings - like an ISO date - I just do this:

Given this:

let isoDate = "2016-05-24T15:31:48.335Z";

I would simply:

let dateOnly = isoDate.split("T")[0];

Javascript experts would probably spit on my grave for suggesting this. But in a sanitized environment like Script Blocks, I’m not actually sure what level of date formatting support exists.


@Bill.French Thank you for this.

I’m all for being lazy and I thought there would be a ‘dirty’ simple way to do this without involving splitting the date into subpart and putting them together again, or trying to hack together some regEx.

Just a bit ashamed I didn’t see this solution myself.

Thanks again