Item date that is parse-able by js

As a small piece of a column script I'm planning to post this week, I thought I'd have a look at formatting dates according to a script-specified format.

JS has some facility to parse date strings that conform to a certain format:

var myDate = new Date(datestring);

datestring has to be in a format parse-able by Date.parse()

I gave that a go with modify and modify_utc. The idea is to do something like:

myDateFormat = "yymmdd"; (...) var myDate = new Date(ColumnData.item.modify); ColumnData.value = myDate.format(myDateFormat);

That won't work with the strings offered by modify and modify_utc.

I'm sure the question of converting a column date to a JS Date has come up before.
What would be the best way to do it?

modify and modify_utc are not strings, they are VT_DATE variants. (If you use them in a context that requires strings, Javascript might turn them into strings, but they aren't strings coming out of Opus.)

var javaScriptDate = new Date(item.modify); should work.

Thank you very much Leo, I had completely missed that they aren't strings even though it clearly says so on the Item page.

Did you mean to add a toString() ?

EDIT: running some more tests, thank you.

Why would you want a toString() there? The whole point is they aren't strings.

Okay, looks like I misunderstood where the problem was.
My format function was broken.
Sorry about the confusion, it's a waste of a thread. :slight_smile:

I'll go run some more tests.
Thank you Leo & Jon!

It seemed useful, so I branched it out into its own Add-In script: Format My Date

Hoping to post the main script I've been working on in the next couple of days. :slight_smile: