SQL server Query time tips

Source: Internet
Author: User
Tags sql server query

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.