Question

Table1

id         int        pk
searchdate datetime
amount     float

Data for Table1

id   searchdate   amount
1    2014-02-05    100
2    2014-02-02    245
3    2014-02-11    344

here i want data between 2014-02-01 to 2014-02-10, but what i want from datetime picker is "01-02-2014" (dd-mm-yyyy format). please help me to create MySQL between query.

Was it helpful?

Solution 2

This stackoverflow question slove my problem .. Link for Answer

Query..

Select * from Table1 where searchdate >= '2014-02-01 00:00:00' and searchdate <= '2014-02-10 00:00:00'

OTHER TIPS

Don't use string conversions at all. Use a PreparedStatement, and the setTimestamp method.

// TODO: Cleanup etc
PreparedStatement st = conn.prepareStatement(
    "select * from table1 where searchdate >= ? and searchdate < ?");
st.setTimestamp(1, startDateTimeInclusive); // java.sql.Timestamp values
st.setTimestamp(2, endDateTimeExclusive);

Unless your ultimate intention is a string, you should avoid string conversions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top