1. Convert time into a string:
Copy codeCode: convert (varchar, field name, 120) -------- yyyy-mm-ddhh: ss: mm0000
Convert (char (10), field name, 120) ------ yyyy-mm-dd
2If you are using the SQL Editor (a tool provided by Microsoft), you do not need to use function conversion to query the date. For example:
SQL codeCopy codeThe Code is as follows: select * frominfowheredatatime> '2017-11-1100:00:00 'anddatetime <'2017-12-am'
3If you use hibernate to query data (using HQL), you cannot use the above method. Because the query is an object, you must ensure that the passed parameter is of the Date type when passing the parameter, otherwise, a "Conversion error" message is displayed"
Java codeCopy codeThe Code is as follows: frompersonaspwherep. date =: date
Passed parameter: date must be of the Date type.
4In the Date query, we found that the database content is yyyy-mm-dd00: 00: 00000 will be accurate to milliseconds, but if we use the Calendar class to get the Date type, there is no way to accurate to milliseconds, that is, we can only get the maximum yyyy-mm-dd00: 00: 00xxx milliseconds is the system's milliseconds at that time, then the query will have an error
5Time Range Query
For example, if you want to query the information between and, the default query time is
2011-11-1100:00:00 to 2012-12-, that is, the time between 2012-12-1223:59:59 seconds cannot be queried.
Solution: 1 second in advance of the query start time, and 1 second in advance)