Results 1 to 1 of 1
  1. #1
    op2 is offline Member
    Join Date
    Oct 2011
    Rep Power

    Default JDBC compare Dates

    i have a problem i cant compare dates and times in java...
    im saving the date in Date format in the phpmyAdmin in Sql, also the Time
    and i cant compare dates with this code:

    Java Code:
    if(checkDate && checkTime)//both 
    sqlStm = "SELECT * FROM "+tableName+" WHERE startDate >= "+startDate2+" AND exitDate <= "+exitDate2+" AND "+"startTime >= "+startTime2.getTime()+" AND exitTime <= "+exitTime2.getTime(); 
    else if(checkDate && !checkTime) //By date 
    sqlStm = "SELECT * FROM "+tableName+" WHERE startDate >= "+startDate2+" AND exitDate <= "+exitDate2; 
    else if (checkTime && !checkDate) //By time 
    sqlStm = "SELECT * FROM "+tableName+" WHERE startTime >= "+startTime2.getTime()+" AND exitTime <= "+exitTime2.getTime(); 
    else //show all 
    sqlStm = "SELECT * FROM cardata ORDER BY `totalPayment` DESC";
    any solutions guys???
    please help me

    this is my insert:

    Java Code:
    PreparedStatement statement = connection 
    .prepareStatement("INSERT INTO `ParkingLot`.`cardata` (`startDate`,`startTime`,`exitDate`,`exitTime`,`carNumber`,`totalPayment`) VALUES (?,?,?, ?,?,?) "); 
    statement.setDate(1, new Date(startDate.getYear(), startDate.getMonth(), startDate.getDay()+16)); 
    statement.setTime(2, new Time(startTime.getHours(), startTime.getMinutes(), startTime.getSeconds())); 
    statement.setDate(3, new Date(exitDate.getYear(), exitDate.getMonth(), exitDate.getDay()+16)); 
    statement.setTime(4, new Time(exitTime.getHours(), exitTime.getMinutes(), exitTime.getSeconds()));
    Last edited by Fubarable; 10-30-2011 at 08:32 PM. Reason: code tags added

Similar Threads

  1. Dates sometimes off by a day?
    By saggio in forum Advanced Java
    Replies: 13
    Last Post: 12-08-2010, 05:56 PM
  2. Help with dates
    By bumblyb33 in forum New To Java
    Replies: 1
    Last Post: 02-13-2009, 03:54 PM
  3. How to Compare two Dates
    By Java Tip in forum java.util
    Replies: 1
    Last Post: 06-24-2008, 07:05 AM
  4. Replies: 0
    Last Post: 04-01-2008, 10:17 AM
  5. Replies: 0
    Last Post: 09-28-2007, 12:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts