Now() but inside SDK

Cannot seem to find this, does anyone know how to get the current date and time when making a Pack?

Looked at Dates and time samples - Coda Pack SDK as well as tried going through all the attributes from coda, pack, and context but to no avail

You mean in JavaScript? You have the Date object to work with dates, to get the current date you can do const now = new Date();

2 Likes

Ohh, now I feel silly! Never occured to me I could use normal js, thanks! :partying_face:

1 Like

One important note is that =Now() is a volatile formula, meaning that Coda regularly recalculates the value. This is what allows it to update on it’s own. Packs can’t create volatile formulas, so a formula that returns new Date() would output the time when it was first run, but it wouldn’t be automatically recalculated and updated.

Also, I’ve put together a doc that translates Coda formulas into their equivalent JavaScript, if you find yourself looking for another alternative:

4 Likes

Oh that doc is awesome and super helpful, thanks!

Yeah I’ve noticed =Now() causing a lot of recalculations, it’s what made me try to make my own pack in the first place :slight_smile:

You can make =Now() fire less frequently by using the DateTimeTruncate formula. For example, =Now().DateTimeTruncate("minute") will only make it recalculate every minute.

I did a deeper breakdown of this technique in the “How it works” section of this doc:

P.S. - I forgot that the Now() formula also takes that precision value as an optional parameter, like =Now("minute")

1 Like