Reputation: 128
I want to display a picture in angular. There is a start date and end date. Pic should be up by start date and down by end date.
Basically, if today is the start date the pic should be up till the end date.
I have all the pieces but I can't fit them together
const startDate = new Date('02/28/2021');
const endDate = new Date('02/29/2021');
let todaysDate = new Date();
to get the numeric values of the date you can either use
todaysDate.valueOf();
or
todaysDate.getTime()
No need to worry about the html or other part of the code. Just a boolean would do.
Something like
if(condition)
return true; // which would mean display the pic
Upvotes: 0
Views: 229
Reputation: 128
const startDate = new Date('02/27/2021').getTime() - (7 * 24 * 60 * 60 * 1000);
const endDate = new Date('02/30/2021').getTime();
const todaysDate = new Date().getTime();
if(todaysDate >= startDate && todaysDate <= endDate){
} else {
}
Upvotes: 0
Reputation: 21
I think it would be something like this:
return (Math.abs(endDate - startDate) < 7 * 24 * 60 * 60 * 1000) // 1 week in milliseconds
Upvotes: 1