Formatting Dates

I have a database with plenty of ‘zero’ dates in it like this 0000-00-00 00:00:00 and like 0000-00-00

When I come to format dates, any that are ‘zero’ come out as Mon 1 Jan 1900 at 12:00 am for instance. In these cases I would rather not have a date showing but instead put some text/explanation.

If I try a ternary operation, what is the correct way to reference a ‘zero’ date?

The following works BUT not for 0000-00-00, so therefore I must know how the date is formatted in the DB.

dmx-bind:value="serverConnect.data.serverAction[0].data_modified == '0000-00-00 00:00:00' ? 'No date entered' : serverConnect.data.serverAction[0].data_modified.formatDate("ddd d MMM yyyy")"

I suppose I could set the comparison date as less than Mon 1 Jan 1900 at 12:00 am,
ie < 1900-01-01

Hope this makes sense.

Any thoughts from anybody?

Use the starts with formatter instead:

dmx-bind:value="serverConnect.data.serverAction[0].data_modified.startsWith("0000") ? ... : ...."
1 Like

The Date object range is -100,000,000 days to 100,000,000 days relative to 01 January, 1970 UTC in which is why you get that date when you evaluate a zero date

You could convert the date to a timestamp (.toTimestamp) which returns the offset as a number which i think should be 0 (not actually tried) and check for that

Edit: or may return a milliseconds offset like -2208988800

Hello sir,
I have a hidden (auto insert) date field that is defaulting to 1970…i tried to apply this tips, but not getting it.
Please assist.

The date 1970-01-01 is the default date inserted when an empty string is inserted into a MySQL date field.

You are probably inserting an empty value

I am trying to insert a timestamp, i.e the current time of registration.

How are you doing this?

The easiest way is to simply set the default at database level to CURRENT_TIMESTAMP or you can do this from a query by setting the value to NOW via the picker

1 Like

Completely skipped my brain. Many thanks

1 Like