0

hello i' trying to take out data from start time and end time from my database record..any idea how to solve it
for example:

2012-09-08 12:09:33 roadA
2012-09-08 10:49:09 roadA
2012-09-08 10:39:27 roadC
2012-09-08 09:09:33 roadA

if i select 10:39:27 to 12:09:33, then only 3 data will be display...

3
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by aravind326
0

I think you are trying to validate of the fetched date is between the given start and end dates. Here is a piece of sample code. Hope you can use it according to your requirement.

    public void checkDates() {
        String startDate = "2012-09-08";
        String endDate = "2012-09-08";
        String startTime = "10:39:27";
        String endTime = "12:09:33";

        String fetchedDate = "2012-09-08 10:49:09";

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        try {
            Date startDt = df.parse(startDate + " " + startTime);
            Date endDt = df.parse(endDate + " " + endTime);
            Date fetchedDt = df.parse(fetchedDate);
            System.out.println("Start : " + startDt + "End : " + endDt + "Fetched : " + fetchedDt);
            if(startDt.before(fetchedDt)&&endDt.after(fetchedDt) ){
                System.out.println("Date " + fetchedDate + " is in between the time limits.");
            }

        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.