Code to hide an elemnt once the item is expired

Hi there,
I can’t seem to find the problem here.
I want the element called “#scaduto” to show only if the date of expiration (“dataFine”) is passed. I don’t know why it’s not working.

My code:
export function repeater1_itemReady($item, itemData, index) {
if (itemData.dataFine > new Date()) {
$w(‘#scaduto’).show();

 } 
 else  { 
	 $w('#scaduto').hide(); 
	 
 } 
 } 

Any idea?
Thanks alot in advance
Cheers

Hello,

The easiest way to compare dates in javascript is to first convert it to a Date object and then compare these date-objects.
Below you find an object with three functions:

  • dates.compare (a,b)
    Returns a number:

  • -1 if a < b

  • 0 if a = b

  • 1 if a > b

  • NaN if a or b is an illegal date
    Then you check to see if the returned number is 1 (1 means a>b) and show and hide accordingly.

Hope this helps,
Majd

Hi Majd,
thank you so much for the tip.
The only problem is, since I’m very new to coding, I wouldn’t know how to integrate it in my code.
Any suggestion would be super helpful.
Once again, thank you so very much.
Cheers