Comparing date inside my class

Hi All,

I am using Firebase as backend for my mobile app. I have a class which contains dates in one column. In my code i am allowing user to make one entry per day which means if entry for particular date is already there then user should not be able to make another entry for the same day. Can someone please share a code snippet to handle this requirement.

Appreciate your help in advance…

For handling dates i always recommend to use moment.js (https://momentjs.com/)
you can use .isSame or .diff (i’m using .diff())
https://momentjs.com/docs/#/query/is-same/
https://momentjs.com/docs/#/displaying/difference/

Can you also suggest, how are you retrieving the date column from DB?

I used to recommend moment, but now I prefer date-fns. It is much more lightweight, more amenable to dead code elimination, and does not require conversion to an object format: it works directly on ISO8601 strings or Date objects.

1 Like

Do you have a code sample for this?

isEqual().

Alright…let me test this. Thanks