Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing date strings using joda time library

Tags:

java

jodatime

I have two date strings say , "2011-04-29" and "2011-01-28" , and i want to compare them using Joda Time. Is there a way to do that ?. An example would be really appreciated.

Thanks

like image 776
Jim Avatar asked Apr 29 '11 11:04

Jim


1 Answers

First you need to parse them. Use DateTimeFormat:

DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd");
DateTime dateTime1 = fmt.parseDateTime(string1);

Then use DateTime.isBefore(..) to compare them:

if (dateTime1.isBefore(dateTime2))
like image 114
Bozho Avatar answered Oct 13 '22 23:10

Bozho