Date component will return Date and Time

I have a Date component with a default value of 7 days form now - {{ moment(new Date(), "DD-MM-YYYY").add(7, 'days')}}

This of course returns a full date/time value.

But the component's value is also a full date/time when I expect it to only be the date portion only:

image

I can of course change the default to {{ moment(new Date(), "DD-MM-YYYY").add(7, 'days').format("YYYY-MM-DD")}} and that fixes things, but it is not the behavior one would expect from a component where you specifically only want the date.

I definitely see what you're saying :thinking:

As a workaround, would using the formattedValue property be helpful at all?

You can add your formatting in the component itself to make the formattedValue whatever you'd like!

That would work in come cases, but I think (could be wrong, have not tested) that when updating your SQL table, it wants the YYYY-MM-DD. If I changed the dateFormat of the component to the DB friendly format, then the user is not happy.

So I'm thinking adding .format("YYYY-MM-DD") is the best workaround for my use case, but yours will be a good one for others.

A realization: Most of what we programmers do is simply translate between the human and the machine and back again. We may do it at different levels - frontend, middleware, backend (or all three) - but that is 90% of our job with a little business logic and workflow control thrown in for spice.

Ooh there's some interesting behavior! When you change the date, it looks like it updates to what you and a database might expect (YYYY-MM-DD, or yyyy-MM-dd in Unicode). See red arrow. But the formattedValue is still customizable. See blue underline.

The initial default date is coming from the Default value field in the component, which is currently set to {{ new Date() }} which I assume has the time already baked in and the component isn't doing anything to cut it off. I'll create a bug report for this not-cutting-off behavior now!

Hi Victoria,

Was the behaviour of this component changed in the end? From my end it looks like I get similar behaviour to Bradley and I'm not sure if this is still intended.

default value -> state inspector value
2022-08-21 -> "2022-08-21"
{{ new Date() }} -> "2023-08-29T15:30:54.030+1000"
{{ moment() }} -> "2023-08-29T15:35:08.411+1000"

Regards,

Stewart

Hi @stewart.anstey! Thanks for checking in! I see the bug report that Victoria created for our eng team to resolve this issue, but it hasn't been fixed yet :disappointed: I'll bump the request internally & post here if we get any updates!

1 Like