30
Apr/10
1

Selecting MySQL Rows with Timestamp Column in a date range from a Java Program

You have a MySQL database table with a Timestamp column, and you need to select a range of dates in which you need to select entries from.

As ever a SELECT statement with a WHERE clause is needed. The following will give you a range of dates from the first to the last. Note that without times specified it is the start of each day. So although 2008-08-31 is specifed no entries on that date will actually be included in the returned results.

String sqlWhereDate =
                " order_placed BETWEEN \”1995-05-01\” AND \”2008-08-31\” ” ;

String sql = “SELECT * FROM orders WHERE ” + sqlWhereDate ;

Tagged as: