Solved

count days between dates - easy and very urgent

Posted on 2004-09-16
6
272 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
6 Comments
 
LVL 18

Expert Comment

by:armoghan
ID: 12081907
0
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 92

Accepted Solution

by:
objects earned 200 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now