简体   繁体   中英

How to convert date to mysql date format

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.

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.

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM