Last Friday, to do a PHP connection to both the MySQL database and the SQL Server database
MySQL has been used to SQL Server is not very familiar with, so stones. No other at least MySQL and SQL Server are relatives
When you make a conditional query. There's been a problem.
First of all, the time of the query is this format
2009 10:20:20AM
I open the SQL Server database to view the data in the table
It's 2009-11-30 10:20:20.233.
Then I checked. It seems that SQL Server has a format problem, but the output of the time is 2009-11-01, there is no way, only in the query data after the conversion of their own
Under MySQL.
For example, I want to find data for time from 2009-11-01 to 2009-11-30.
SELECT * FROM table where time > ' 2009-11-01 ' and Time < ' 2009-11-30 ';
I drew a tiger, and I didn't know where I was going or what I was doing,
I think my 2009-11-01 is really bad compared to one 2009 10:20:20am or 2009-11-30 10:20:20.233, at least not comparable.
So I converted my 2009-11-01 to one 2009 00:00:00am and 2009-11-01 00:00:00.000.
No more than one. In ":" Out of error. It's not uncomfortable!
So uncomfortable to find a day also no point suddenly realize, not because of this small problem, affect my image, this day early woke up,
Yesterday I found SQL Server's time conversion function convert includes many kinds, that is, no 2009-11-01 of this format, do not know whether I am stupid or I am stupid
There is no way, can only be in and out, first convert 2009-11-01 to 20091101 then 2009 10:20:20am or 2009-11-30 10:20:20.233 to 20091130 and then compare,
Don't say, it's a good result.
SELECT * FROM table where convert (varchar (), date_time,112)!< $begin _date and CONVERT (varchar, date_time,112)!& Gt $end _date
(!< and!> almost tripped me up)
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.