Calculating # of days between two dates

Calculating # of days between two dates

Question:
I need help to calculate the number of days between two dates. This may seem like a trivial question, but for the life of me, I cannot find away for the Calendar or Date class to achieve this.

Answer:
This is actually not a trivial question. The Java time classes are ill-suited for performing calendar arithmetic. They seem to have been designed with time storage in mind rather thantime manipulation.

One way to achive what you desire is tocall getTime() in the Date class to obtaina representation of the two dates in secondssince January 1, 1970. You would then subtractthe smaller value from the larger and convertthe resulting number of seconds into days(there are 86,400 seconds in a day). However,you will run into some limitations with therange of dates that can be represented in thismanner. You may have to roll your own code or look for a third-party solution.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several