PHP Operations SQL Server Little insights on time-date reading _php tutorial

Source: Internet
Author: User
In the Friday, to do a PHP simultaneously to the MySQL database and SQL Server database connection Dongdong
I used to use MySQL to be not very familiar with SQL Server, so stones. No, at least MySQL and SQL Server are relatives.
When you make a conditional query. There is a problem
The first is that the query time is this format
10:20:20am
I open the SQL Server database to view the data in the table
It was 2009-11-30 10:20:20.233.
Later looked like SQL Server has a format problem, but the output of the time to want is 2009-11-01, there is no way, only after the query out the data after the conversion of a
Under MySQL.
For example, I want to find data for time periods 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 had no idea where I was going, and I didn't have any effect.
I think my 2009-11-01 is really bad compared with one of the 10:20:20am or 2009-11-30 10:20:20.233, at least comparable
So I converted my 2009-11-01 to 00:00:00am and 2009-11-01 00:00:00.000
No more than one. In the ":" Error. It's not uncomfortable!
So uncomfortable looking for a day also did not point suddenly small enlightenment, not because of this small problem, affect my image bar, today, early morning woke up,
Yesterday I found the time conversion function of SQL Server convert includes many kinds, that is, no 2009-11-01 this format, do not know whether I am stupid or stupid
There is no way, only a medium and a bit, first convert 2009-11-01 to 20091101 and then the 10:20:20am or 2009-11-30 10:20:20.233 converted into 20091130 and then compare,
Don't say it, it's a real result.
SELECT * FROM table where convert (varchar (ten), date_time,112)!< $begin _date and CONVERT (varchar), date_time,112)!& Gt $end _date
(!< and!> also almost tripped me)

http://www.bkjia.com/PHPjc/321001.html www.bkjia.com true http://www.bkjia.com/PHPjc/321001.html techarticle In Friday, to do a PHP simultaneously to the MySQL database and SQL Server database connection east has been using MySQL is not very familiar with SQL Server, so stones. Nothing else to ...

  • 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.