Views on SQL Server read time and date in php

Source: Internet
Author: User

Last Friday, we made a php connection to both the mysql database and the sqlserver database.
I have been using mysql for a long time and I am not very familiar with sqlserver. None of them, at least mysql and sqlserver, are relatives.
When performing a conditional query. An error occurred.
First, the query time is in this format.
11 30 2009 10:20:20 AM
I open sqlserver database to view table data
It is 10:20:20. 233
Later, I checked it and it seems that sqlserver has a format problem, but the output was. There is no way. I can only convert it after querying the data.
In mysql
For example, if you want to query data in the period from
Select * from table where time> '2017-11-01 'and time <'2017-11-30 ';
I drew a tiger, but I don't know where I am going,
I think my is indeed not as good as 11 30 2009 10:20:20 AM or 10:20:20. 233, at least not comparable
So I switched my to 11 01 2009 00:00:00 AM and 00:00:00. 000
Another one is worse. An error occurs in. Isn't that uncomfortable!
So it's not easy to find me for a day. I can't influence my image because of this small problem. I woke up early today,
I found the convertime Conversion Function convert yesterday. There are many convert types, that is, I don't know whether I am stupid or I am stupid.
No way. You can only replace it. First, convert 2009-11-01 to 20091101, then convert 11 30 2009 10:20:20 AM or 2009-11-30 10:20:20. 233 to 20091130, and then compare,
Let alone, it's really a result.
Select * from table where convert (varchar (10), date_time, 112 )! <$ Begin_date and convert (varchar (10), date_time, 112)!> $ End_date
(! <And!> I almost caught up with me)

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.