How to get Weeks as a negative number in JodaTime?

Viewed 33

This is the current code am working with :

 int weeks = Weeks.weeksBetween(movieReleaseDate, new DateTime()).getWeeks();

If the movie was released 8 weeks ago, it gives me the correct output as 8. How do I make it return -8 ? To return a negative weeks seems to be the simplest hack which I do not want to do.

1 Answers

You can simply reverse the parameters order:

int weeks = Weeks.weeksBetween(new DateTime(), movieReleaseDate).getWeeks();

This will give negative result if the first parameter is after the second one.

Related