I wanted the display the records only after 5 mins from the current timestamp.
Below is my HTML Code,
<div *ngFor="let bookings of newBookings" class="card mb-4">
<div *ngIf="isTimestampAfterCurrent(bookings?.currentTimeStamp)" class="card-body">
....
</div>
</div>
In my component.ts
isTimestampAfterCurrent(timestamp: string): boolean {
if (!timestamp) {
// If timestamp is not available, display the booking
return true;
}
const currentTimestamp = moment(); // Get the current timestamp
const bookingTimestamp = moment(timestamp, 'YYYY-MM-DD HH:mm:ss');
console.log(bookingTimestamp);
return bookingTimestamp.isAfter(currentTimestamp.add(5, 'minutes'));
}
Note: Format of the currentTimeStamp = 2023-06-25 02:29:49
The problem is in the last line of your code. The
.add()function only mutates theMomentobject but doesn't seem to return it.Here is a working example: