In the computer room toll system, there are several cases where:
Start date and end date, believe that smart you can certainly imagine why there are two date controls! Yes, it is from a table to find out in these two date range class records!
Some people say, it's not easy!
If we define the first control as begin, the second control is defined as a over! So the query statement is not
Copy Code code as follows:
"SELECT * from Recharge_info where date< '" & Over.value & "' and Date> '" & Begin.value & ""
What's so hard about this! However, the fact is not so simple, if the query is written like this, you are sure not to find out, so how can we in the SQL Server to compare the size of two date?
Here we're going to borrow the convert () function.
The CONVERT () function is a common function that converts dates to new data types.
The CONVERT () function can display date/time data in a different format.
Syntax: CONVERT (data_type (length), Data_to_be_converted,style)
where data_type (length) sets the target data type (with optional length) data_to_be_converted the output format that contains the value style that needs to be converted, the date time
Where you can use the style value:
For example:
Copy Code code as follows:
Print convert (varchar (), GETDATE ())
Print convert (varchar), GETDATE (), 110)
Print CONVERT (varchar (one), GETDATE (), 106)
Print convert (varchar), GETDATE (), 113)
The results are as follows:
If you use a date lookup record in SQL Server, if you use a date= ' 2013-09-22 ' query, but you can still find out what you want, remember: it's not the date that you want to record in the table. But the date in the table this string is equal to the ' 2013-09-22 ' string!