Comparing date inside my class


#1

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…


#2

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/


#3

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


#4

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.


#5

Do you have a code sample for this?


#6

isEqual().


#7

Alright…let me test this. Thanks