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