{
//Check if the events are happening today
const isEventHappeningToday = events => {
const today = dayjs().startOf('day')
for (const event of events) {
const eventDate = dayjs(event.date.seconds * 1000).startOf('day')
if (eventDate.isSame(today, 'day') && event.status === 'active') {
return true
}
}
return false
}
//return
{isEventHappeningToday ? (
<div className='badge badge-secondary'>Happening Today!</div>
) : null}
}
Result-
Each and every events are now happening today. Have to make ‘Happening Today!’ show up to only events which are happening to today’s date. How do i do this?
2
Answers
You can do like this:
To check if events are happening today in a .jsx file, you need to use JavaScript’s Date object to compare the current date with the date of the events. Here’s an example of how you can accomplish this:
In the above example, we create an array
events
that contains objects withname
anddate
properties. We then create a new Date objecttoday
to represent the current date. We use thefilter
method to iterate through theevents
array and compare each event’s date with today’s date. The events happening today are stored in theeventsToday
array, which you can then use as needed.