Hi .Difference between two Dates

Hi .Difference between two Dates

View Answers

December 23, 2008 at 11:16 PM

Hi friend,

Code to solve the problem :

import java.util.*;
public class DateDifference {
public static void main(String args[]){
DateDifference difference = new DateDifference();
}
DateDifference() {
Calendar cal1 = new GregorianCalendar();
Calendar cal2 = new GregorianCalendar();

cal1.set(2008, 8, 1);
cal2.set(2008, 9, 31);
System.out.println("Days= "+daysBetween(cal1.getTime(),cal2.getTime()));
}
public int daysBetween(Date d1, Date d2){
return (int)( (d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24));
}
}

Thanks









Related Tutorials/Questions & Answers:
Hi .Difference between two Dates - Java Beginners
Hi .Difference between two Dates  Hi Friend.... Thanks for ur Very good response.. Can u plz guide me the following Program.... difference between two dates.. I need to display the number of days by Each Month
calculate difference between two dates
calculate difference between two dates  hi, I was actually working on to calculate the number of days between two dates of dd/mm/yyyy format... the difference between the two dates
Advertisements
to calculate the difference between two dates in java - Java Beginners
to calculate the difference between two dates in java  to write a function which calculates the difference between 2 different dates 1.The function should accept 2 different dates (in the format dd/mm/yyyy hh:mm:ss AM/PM) 2.The
display dates between two dates - Java Beginners
display dates between two dates  hi can any one help me to writing this code, i need to store the dates between to dates so that i can retrive the data from the db using theses dates. its urgent pls tell me as possible
Difference in two dates - Java Beginners
on that. The thing is, that I need to find the difference between the two dates in JAVA... the difference between two dates. public class DateDiffDemo { public static...Difference in two dates  Hello there once again........ Dear Sir
calculate difference between two time in jsp
calculate difference between two time in jsp  How to calculate difference between two dates
mysql difference between two numbers
mysql difference between two numbers  How to get total bate difference between two dates for example 1/01/2012 and 1/02/2012 in MYSQL?   ... between two date. The syntax of DATEDIFF is .. SELECT DATEDIFF('2012-01-31 23:59
days between two given dates using PHP
days between two given dates using PHP  How can we know the number of days between two given dates using PHP?   Hi friends, Example: <html> <head> <title>Number of days between two
list of all months between two dates in java
list of all months between two dates in java  Hi, I want to get list of all months with year between two dates. How to do this in Java? Thanks   Hi, This is the example code which can be used: package test.app
list of all months between two dates in java
list of all months between two dates in java  Hi, I want to get list of all months with year between two dates. How to do this in Java? Thanks   Hi, This is the example code which can be used: package test.app
JavaScript check if date is between two dates.
JavaScript check if date is between two dates.  Check if date is between two dates?   <html> <head> <title>Date before...;/head> <body> <h2>Check if date is between two dates</h2>
How to select Data Between Two dates in Java, MySQL
How to select Data Between Two dates in Java, MySQL  How to select Data Between Two dates in Java, MySQL? Thanks in advance.   http://www.v7n.com/forums/coding-forum/294668-how-select-data-between-two-dates-php
Javascript calculate number of days between two dates
Javascript calculate number of days between two dates In this tutorial, you will learn how to calculate number of days between two dates.For this, you need... using Date.getTime() function. Once both Dates have been converted, subtracting
Mysql Time Difference Function
difference between any two dates. Understand with ExampleADS_TO_REPLACE_1 The Tutorial... that return you the time difference between any two consecutive dates. TimeDiff('Year1 Time1', 'Year2 Time2') : The Query performs the time difference between
mysql between dates not between dates
mysql between dates not between dates  I am trying to list the data between dates and not between dates using join method ..but that not working for me
Jdbc connectivity in java to oracle for retrieving data between two dates
Jdbc connectivity in java to oracle for retrieving data between two dates  Dear Sir, I Need a program in which i want to retrieve the data b/w two dates from the database table. I am using combo box to get the date. Problem
display diffrence between two dates in a text box - JSP-Servlet
display diffrence between two dates in a text box  i have these set of codes // String di=request.getParameter("timestamp2"); String d2=request.getParameter("timestamp3"); SimpleDateFormat formater=new SimpleDateFormat("dd-mm
Java Swing Date Difference
Java Swing Date Difference In this tutorial, you will learn how to find the difference between two dates. Here is an example that accepts two dates from... the following method that calculates the date difference in terms of days
How can we know the number of days between two given dates using PHP?
How can we know the number of days between two given dates using PHP?  How can we know the number of days between two given dates using PHP
what is difference between one-way data binding and two-way data binding?
what is difference between one-way data binding and two-way data binding?  what is difference between one-way data binding and two-way data binding? Thanks
What is the difference between the >> and >>> operators?
What is the difference between the >> and >>> operators?   hi, What is the difference between the >> and >>> operators? Thanks
difference between == and === operators?
difference between == and === operators?  Is (====) operator available in java or not? difference between
Difference between DispatchAction and LookupDispatchAction
Difference between DispatchAction and LookupDispatchAction  What is the Difference between DispatchAction and LookupDispatchAction
difference between SessionState and ViewState
difference between SessionState and ViewState  What is the difference between SessionState and ViewState
difference between ForwardAction and IncludeAction
difference between ForwardAction and IncludeAction  What is the difference between ForwardAction and IncludeAction
Difference between struts and JSF
Difference between struts and JSF  What is the difference between struts and JSF
Java get number of days between dates
the number of days between the two described dates. In order to get the number of days between two dates, the given example has set two dates by using... returns the number of days between two dates:ADS_TO_REPLACE_2
Date Difference
Date Difference       This example learns how to make the difference between two dates and how... Object class and makes a difference between a Date object and a set of integer
difference between varchar & varchar2?
difference between varchar & varchar2?  What is the difference between varchar & varchar2
Difference between 3d and 4d
Difference between 3d and 4d  what is the difference between 3d and 4d
difference between lock and synchronization
difference between lock and synchronization  Hi, I am new in java please anyone tell me difference between lock and synchronization in java. its urgent. Thank in advance   Please visit the following link: Lock
What is the difference between hibernate and spring
What is the difference between hibernate and spring  Hi, What is the difference between hibernate and spring. Thanks
Difference between forward and sendRedirect
Difference between forward and sendRedirect  What's the difference between forward and sendRedirect?   RequestDispatcher.forward() and HttpServletResponse.sendRedirect() are the two methods available for URL redirecting
What is the difference between a constructor and a method?
What is the difference between a constructor and a method?  Hi, What is the difference between a constructor and a method?   Hi, I have found a good link of Java program related to difference between constructor
Difference between Mysql and SQL
Difference between Mysql and SQL  hello, What is the difference between Mysql and SQL??   hii,ADS_TO_REPLACE_1 SQL is structural quary language but mysql is database package
Difference between Timer and Thread?
Difference between Timer and Thread?  Can anyone tell me about the difference between Timer and Thread, Why we need to have Timer in case we have Thread implimentation startegy in Java
what is the difference between extends and implements
what is the difference between extends and implements  difference between extends and implements
what is the difference between extends and implements
what is the difference between extends and implements  difference between extends and implements
Difference between SCJP Exams
Difference between SCJP Exams  What is the differences between SCJP 5 (310 - 055) exam and SCJP 6 (310 - 065) exam??? Thank You In Adv
Difference between JSP and Servlets
Difference between JSP and Servlets  What is the difference between JSP and Servlets ?   JSP is used mainly for presentation only. A JSP can only be HttpServlet that means the only supported protocol in JSP is HTTP
difference between prepared statement and statement
(),jtextfield2.getText()); whats the difference between these two and which is more...difference between prepared statement and statement  i mean in prepared statement we write insert command as INSERT INTO tablename VALUES
Difference between request.getRequestDispatcher() and context.getRequestDispatcher()
Difference between request.getRequestDispatcher() and context.getRequestDispatcher()  What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?   request.getRequestDispatcher
Difference between http and https
Difference between http and https  Difference b/w HTTP and HTTPS please provide answer in tabular form.   Hi Friend, Differences: 1)HTTP is hyper text transfer protocol which is responsible for transmitting
Difference between ServletContext and ServletConfig
Difference between ServletContext and ServletConfig   What is the difference between ServletContext and ServletConfig?   ServletContext :Defines a set of methods that a servlet uses to communicate with its servlet
Difference between translate and replace
Difference between translate and replace   hiii, What is the difference between translate and replace?   hello,ADS_TO_REPLACE_1 Replace replace every instence of character with character sting by the given charator
difference between applet and swings
_TO_REPLACE_3 Thanks   Hi Friend, Difference between Swing and Applet:ADS...difference between applet and swings  what are the major difference between swing and applets   Hello Friend, Differences:ADS_TO_REPLACE_1
Difference between GET and POST
Difference between GET and POST   Difference between GET and POST ?   The difference between a GET and a POST is the way data is transferred to a servlet. With a GET, the URL will show each name/value pair on the query
What is the difference between PHP4 and PHP5?
What is the difference between PHP4 and PHP5?  What is the difference between PHP4 and PHP5
What is difference between a PROCEDURE & FUNCTION ?
What is difference between a PROCEDURE & FUNCTION ?  What is difference between a PROCEDURE & FUNCTION
Difference between XML and HTML - XML
Difference between XML and HTML  What is the basic Difference between XML and HTML

Ads