How can I compare if mytime
is between fromtime
and totime
:
Timestamp fromtime; Timestamp totime; Timestamp mytime;
The compareTo() method of Timestamp class returns : Integer value 0 if this Timestamp object is equal to given Timestamp object. A value less than 0 if this Timespan object is before the given argument. A value greater than 0 if this Timespan object is after the given argument.
The recommended way to compare two LocalDateTime objects is using provided methods which compare both date-time parts and return a boolean value – true or false . These methods only consider the position of the two dates on the local timeline and do not consider the chronology, or calendar system.
To calculate the difference between the timestamps in MySQL, use the TIMESTAMPDIFF(unit, start, end) function. The unit argument can be MICROSECOND , SECOND , MINUTE , HOUR , DAY , WEEK , MONTH , QUARTER , or YEAR . To get the difference in seconds as we have done here, choose SECOND .
if(mytime.after(fromtime) && mytime.before(totime)) //mytime is in between
Use the before
and after
methods: Javadoc
if (mytime.after(fromtime) && mytime.before(totime))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With