如何将日期转换为mysql日期格式

Vij*_*jay 1 java mysql between

表格1

id         int        pk
searchdate datetime
amount     float
Run Code Online (Sandbox Code Playgroud)

表1的数据

id   searchdate   amount
1    2014-02-05    100
2    2014-02-02    245
3    2014-02-11    344
Run Code Online (Sandbox Code Playgroud)

我想要data between 2014-02-01 to 2014-02-10,但我想要的datetime picker"01-02-2014" (dd-mm-yyyy format).请帮我在查询之间创建MySQL.

Jon*_*eet 6

不要使用字符串转换可言.使用a PreparedStatementsetTimestamp方法.

// 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);
Run Code Online (Sandbox Code Playgroud)

除非您的最终意图是字符串,否则您应该避免字符串转换.