Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date arithmetic

 
Simon Good
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
How do I go about calculating the number of days between two dates? Is there a simple way to do it?
Thanks
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on what answer you want
how many days between monday and friday - 5?
how many days between 15th and 19th - 4?
actual days in-between 15th and 19th = 3
You can convert the dates to milliseconds, then subtract dt1 from dt2, then
convert the result back to days.
Here's a way where you can easily change the code, depending on the output
you want.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic