Title: Need If Expression to compare time and date in Jmeter
Tags: jmeter
Question: I have a requirement where I need to compare two dates and time,
I am testing few REST APIs where the dates dynamically change after 8:00 AM for example basically my application provides data for 1 day:
If the UTC time is not 8 AM my application will display data for past one day
&quot;GET data for Assets During 2021-11-28T8:00:00 to 2021-11-29T8:00:00&quot;
But when UTC time  is more than 8 AM for current date API date will dynamic change to next day
&quot;GET data for Assets During 2021-11-29T8:00:00 to 2021-11-30T8:00:00&quot;
I am planning to run a Soak test for 48 hr, if any one can provide a statement to compare, I can use timeshift function to either go to set of APIs when time is still not 8AM ${__timeshift(YYYY-MM-dd,-P1D))T08:00:00 and ${__timeshift(YYYY-MM-dd,P1D)) after 8 AM.
Thanks,


Here is the accepted answer: I think you will need to go for __groovy() function and Calendar class, something like:

will execute if current UTC hour is later than 8
```${__groovy(Calendar.getInstance(TimeZone.getTimeZone('UTC')).get(Calendar.HOUR_OF_DAY) &gt; 8,)}
```

will execute if current UTC hour is earlier than 8
```${__groovy(Calendar.getInstance(TimeZone.getTimeZone('UTC')).get(Calendar.HOUR_OF_DAY) < 8,)}
```


should do the trick for you.
More information: 6 Tips for JMeter If Controller Usage



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:11/29/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<jmeter>', 'Title': 'Need If Expression to compare time and date in Jmeter', 'ViewCount': 68, 'id': 70152386, 'user_AboutMe': None, 'user_AccountId': 2537901.0, 'user_DisplayName': 'Akshat', 'user_Reputation': 49.0, 'user_Views': 5.0, 'user_id': 2204487.0}}