Can't format Date List

Hi there!

I’ve created a simple formula, that creates a list of dates:

It points out that these are datetime values, other formulas can also normally use this constant.

But when I change the format, it breaks:

Any ideas?

Thanks!

Yep that column format only works for single dates. As far as I know the most appropriate way to do this is by kind of building the format manually, like

[…all those dates you generated]
  .ForEach(
    Format(
      “{1}/{2}/{3}”,
      CurrentValue.Month(),
      CurrentValue.Day(),
      CurrentValue.Year()
    )
  )

Don’t quote me on the exact month day year formulas but something like that

1 Like

That reply was super quick!
Sadly, in my use case, I need the formula result for further calculations, therefore can’t actually map it to a nice string.

Thanks for letting me know that this is an issue! :slight_smile:

Ah ok, have run into the same problem.

There’s also the unsupported secret formula formatDateTime() you could explore. But I haven’t used it and I’m not sure if it outputs strings or datetimes or what.

Could also do a column that keeps it datetimes and a second pretty column that shows the texts

1 Like

FormatDateTime() does in fact output datetime values (it will even convert to a datetime if you feed it a string or number). However, it’s a little awkward to specify the format—it’s just an integer from 1-29, presumably the index of Coda’s builtin list of formats.

If that’s too awkward, or if you don’t want to use an unsupported formula (which could change or break any day), then @Nick_HE’s other option works too, and you just have to convert back into a list of dates wherever you want to use that value like so:

[list of strings].ForEach(ToDate(CurrentValue))

Just keep in mind, if you choose another format, that ToDate("1/12/23") ⇒ January 12 (NOT December 1). At least for me it does; I don’t know if changing your locale might affect that.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.