Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

count days between dates - easy and very urgent

Posted on 2004-09-16
6
Medium Priority
?
319 Views
Last Modified: 2012-06-27
Hi, I just need code that counts the number of days between two dates which are in the following format:

String date1 = "dd-MM-yyyy";
String date2 = "dd-MM-yyyy";

Thank you.
0
Comment
Question by:iAwin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 18

Expert Comment

by:armoghan
ID: 12081912
check this link as well
http://www.faqs.org/qa/qa-10170.html
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12081913
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 92

Accepted Solution

by:
objects earned 800 total points
ID: 12081969
SimpleDateFormat sdf = new SimpleDateFormat("mm-MM-yyyy");
Date d1 = sdf.parse(date1);
Date d2 = sdf.parse(date2);
int days = d2.getTime() - d1.getTime())/1000/60/60/24;
0
 
LVL 3

Expert Comment

by:nesnemis
ID: 12082042
You can use this function...

private long countDays(String date1, String date2)
      {
            String date[] = date1.split("-");
            Calendar d1 = new GregorianCalendar(Integer.parseInt(date[2]), Integer.parseInt(date[1]), Integer.parseInt(date[0]));
            
            date = date2.split("-");
            Calendar d2 = new GregorianCalendar(Integer.parseInt(date[2]), Integer.parseInt(date[1]), Integer.parseInt(date[0]));
            
            long diff = d1.getTimeInMillis() - d2.getTimeInMillis();
            if(d1.before(d2))
                  diff = d2.getTimeInMillis() - d1.getTimeInMillis();
            
            return diff/(24*60*60*1000);
      }
0
 

Author Comment

by:iAwin
ID: 12198777

Thanks :)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question