1. Convert time to String form:
Copy Code code as follows:
CONVERT (varchar, field name,)--------yyyy-mm-ddhh:ss:mm0000
Convert (char (10), field name, YYYY-MM-DD)------
2, if you are using the SQL editor (Microsoft's own tools), the query date does not need to use a function conversion, for example
SQL code
Copy Code code as follows:
Select*frominfowheredatatime> ' 2012-11-1100:00:00 ' anddatetime< ' 2012-12-1200:00:00 '
3, if the use of Hibernate to query the data (using HQL) can not use the above method, because the query is the object, then the parameter passed to ensure that the passed parameter is the date type, or you will be prompted "conversion error"
Java code
Copy Code code as follows:
Frompersonaspwherep.date=:d ate
Parameters passed: Date must be of date type
4, we found that the contents of the database were yyyy-mm-dd00:00:00000 to milliseconds after the date query, but if we use the Calendar class to get the date type, there is no way to be precise to milliseconds, We can only get yyyy-mm-dd00:00:00xxx milliseconds is the millisecond of the system, then the query will have errors
5, time interval segment query
For example, I would like to query the information between 2011-11-11 and 2012-12-12, and its default query time is
2011-11-1100:00:00 to 2012-12-1200:00:00, which means that 2012-12-1223:59:59 seconds are not queried.
Workaround: Start the query 1 seconds ahead of time, one more day (1 seconds less)