When I use now() I get the date and time in this format:
2/14/2023 11:05:35 AM
To save space, is there a way to reformat the output to:
2/14/23 11:05 AM
Many thanks!
Gregg
Thank you!
I feel stupid asking this…but how did you get to that screen?
I know how to get to date and time options for a field…but in this application the field is a combination of now()+text.
This is a page formula, so in a page I typed =
and put the formula in, Now()
, then pushed the date/time icon in the top right of the popup, and selected the format you mentioned.
Thank you for your help…I see how to do that now.
That doesn’t seem to help in this case though, because the field is a text formatted formula:
Format(now())+": "+LineBreak()+thisRow.Notes
Ah, in the case of merging multiple pieces of text together, you can use .FormatDateTime().
Now().FormatDateTime(2,2)
Hi @Gregg_Stebben !
Now() takes a precision optional input such as "second"
, "minute"
, "hour"
and "day"
(the default being "second"
).
So, using:
-
Now()
orNow("second")
will output something like:3/3/2023 10:11:12 AM
(M/D/YYYY hh:mm:ss A
) and will refresh every seconds
-
Now("minute")
will output something like:3/3/2023 10:11 AM
(M/D/YYYY hh:mm A
) and will refresh every minutes
-
Now("hour")
will output something like:3/3/2023 10:00 AM
(M/D/YYYY hh:00 A
) and will refresh every hours
-
Now("day")
is the equivalent toToday()
and will output something like:3/3/2023
(M/D/YYYY
) and will refresh every days
And I have a small suggestion to make here, regarding this :
Why not use a formula such as:
Format(
"{1}: {2}{3}",
Now("minute"),
LineBreak(),
thisRow.Notes
)
In this Format() formula the placeholders in the template ("{1}: {2}{3}"
) will be replaced, once the formula runs, by :
{1}
→Now("minute")
{2}
→LineBreak()
{3}
→thisRow.Notes
Which should give you the same result you probably already have using
Format(now())+": "+LineBreak()+thisRow.Notes
It’s just that it’s not recommended tu use +
to concatenate things within Coda.
+
is, more often than not in these cases interpreted as the addition operator and can lead to weird looking/erroneous results down the line
Thank you so much!
I have seen the use of “{1}{2}{3}” but until now I didn’t understand how it worked…thank you!
And thank you for explaining how the timing with “precision” vs other modifiers works!
Is there a way to get the year to output with two digits (23) vs 4 digits (2023)?
Dear @Gregg_Stebben ,
Kind reminder where it was explained to you how to get the last two digit’s of the year
No problem @Gregg_Stebben !
Yes, but you would need to deconstruct/reconstruct the date according to the format you want
Format(
"{1}/{2}/{3} {4}: {5}{6}",
Today().Month(),
Today().Day(),
Today().Year().Right(2),
Now("minute").ToTime(),
LineBreak(),
thisRow.Notes
)
In which :
{1}
is the placeholder for →Today().Month()
{2}
is the placeholder for →Today().Day()
{3}
is the placeholder for →Today().Year().Right(2)
(Which, in this case, extracts 2 characters fromToday().Year()
starting from the Right()){4}
is the placeholder for →Now("minute").ToTime()
(As the date has been formatted previously withToday()
, only the current time is needed now){5}
is the placeholder for →LineBreak()
{6}
is the placeholder for →thisRow.Notes
This should give you the desired result
Now, to avoid the Today()
redundancy, you can store its value and give it a name using WithName()
And the previous formula becomes :
Today().WithName(T,
Format(
"{1}/{2}/{3} {4}: {5}{6}",
T.Month(),
T.Day(),
T.Year().Right(2),
Now("minute").ToTime(),
LineBreak(),
thisRow.Notes
)
)
Where T
is the name of Today()
's value from which we later get the month, day and formatted year .
I used Today()
instead of Now("minute")
because only the date needed to be manipulated.
(I didn’t see the point of using Now("minute")
multiple times just to get the date from it when there’s Today()
)
Amazing, thank you!!!
No problem @Gregg_Stebben !
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.