How to Select days between two datetime in android?

I have two datetime 09/01/2014 and 09/10/2014.i want to check days between there datetimes. i wrote function witch can to change datetime format

public static String dateFormatterforLukka(String inputDate)
        {
 
            String inputFormat = "MM/dd/yyyy";
            String outputFormat = "d MMM";
 
            Date parsed = null;
            String outputDate = "";
            try
            {
                SimpleDateFormat df_input = new SimpleDateFormat(inputFormat,
                        new Locale("en", "US"));
                SimpleDateFormat df_output = new SimpleDateFormat(outputFormat,
                        new Locale("en", "US"));
 
 
                parsed = df_input.parse(inputDate);
                outputDate = df_output.format(parsed);
            }
            catch (Exception e)
            {
                outputDate = inputDate;
            }
            return outputDate;
        }

but i do not know how i can solve my problem if anyone knows solution please help me

Last updated:11/7/2014 1:27:52 AM

1 Answers

Allen Scott
Allen Scott

You can try this function:

public String getDateDiffString(Date dateOne, Date dateTwo)
{
    long timeOne = dateOne.getTime();
    long timeTwo = dateTwo.getTime();
    long oneDay = 1000 * 60 * 60 * 24;
    long delta = (timeTwo - timeOne) / oneDay;

    if (delta > 0) {
        return 'dateTwo is ' + delta + ' days after dateOne';
    }
    else {
        delta *= -1;
        return 'dateTwo is ' + delta + ' days before dateOne';
    }
}

Answer