Difference between two DatesDifference between two Dateshttps://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=1193388882024-03-28T17:43:37Z2024-03-28T17:43:37ZRE: Difference between two DatesOlaf Kockhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1193459112020-06-09T14:14:25Z2020-06-09T14:14:25Zmake sure you get your timezones right, in case the "penalty" coming in a few hours early or late would be a problem.Olaf Kock2020-06-09T14:14:25ZRE: Difference between two DatesNikolaos Kroustalakishttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1193432602020-06-09T13:01:25Z2020-06-09T13:01:25Z<html><head></head><body>I had some problems with that solution. Fixed it by doing the following: <br><pre><code>[code]@SuppressWarnings( "deprecation" )
int penaltyYear = penalty.endDate.getYear();
int currentYear = currentDate.getYear();
if ((penaltyYear + 4) &lt; currentYear) {
// Invoke penalty
}</code></pre>Thank you so much for your help though.</body></html>Nikolaos Kroustalakis2020-06-09T13:01:25ZRE: Difference between two DatesMohammed Yasinhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1193427872020-06-09T11:20:13Z2020-06-09T11:20:13Z<html><head></head><body>Hi,You can use com.liferay.portal.kernel.util.DateUtil for getting year from Date and subtract it <br><br><pre><code>&nbsp;DateUtil.getYear(endDate) - DateUtil.getYear(currentDate)</code></pre></body></html>Mohammed Yasin2020-06-09T11:20:13ZDifference between two DatesNikolaos Kroustalakishttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1193388872020-06-09T09:55:58Z2020-06-09T09:55:58Z<html><head></head><body>Hello. I have a maven project in Liferay 6.2. There is a requirement in which I must compare an EndDate stored in Oracle DB and the current Date. In order to do so, I have created a scheduled job. I implemented the <strong>receive(Message message)</strong> method, which is the following one:<br><pre><code>&nbsp;&nbsp;&nbsp; @Override
&nbsp;&nbsp; &nbsp;public void receive(Message message) throws MessageListenerException {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;logger.info("Scheduler for checking dates on Penalties has started...");
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ApplicationContext applicationContext = ApplicationContextProvider.getApplicationContext();
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;PenaltyService service = (PenaltyService)applicationContext.getBean("service");
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Date currentDate = new Date();
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;currentDate = dateFormatter.parse(dateFormatter.format(new Date() ));
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} catch (ParseException e) {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;e.printStackTrace();
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("Current date is: " + currentDate);
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;List<penalty> penalties = service.findAll();
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;for (Penalty penalty : penalties) {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (penalty.endDate == null) {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("No EndDate...");
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if (penalty.endDate.before(currentDate)) {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;penalty.setRevocationOrCompletion(1);
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if (penalty.endDate.compareTo(currentDate) == 0) {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;penalty.setRevocationOrCompletion(1);
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("-------------------" + penalty.getEndDate() + " " + penalty.isRevocationOrCompletion());
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp; &nbsp;}</penalty></code></pre><br>I am having some difficulties in implementing the way to compare only the YEAR of those dates an