Home > Backend Development > PHP Tutorial > A little insight into time and date reading in php operating sqlserver_PHP tutorial

A little insight into time and date reading in php operating sqlserver_PHP tutorial

WBOY
Release: 2016-07-21 15:42:17
Original
781 people have browsed it

Last Friday, I wanted to make a PHP connection to mysql database and sqlserver database at the same time.
I had been using mysql before and was not very familiar with sqlserver, so I was crossing the river by feeling the stones. Nothing else, at least mysql and sqlserver are relatives
when doing conditional queries. A problem occurred
First of all, the time queried is in this format
11 30 2009 10:20:20AM
I opened the sqlserver database to view the data in the table
But it was 2009-11-30 10:20:20.233
After checking, it seems that sqlserver has a format problem, but the output is 2009-11-01. I have no choice but to convert it myself after querying the data
Under mysql
For example, I want to find data in the time period 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, but I don't know where my where went and it didn't work.
I think my 2009-11-01 is really bad. Compared with 11 30 2009 10:20:20AM or 2009-11-30 10:20:20.233, at least it is not very comparable
So I converted my 2009-11-01 to 11 01 2009 00:00:00AM It is even worse to compare it with 2009-11-01 00:00:00.000
. An error occurred at ":". Isn’t this uncomfortable?
So I searched awkwardly for a whole day without any sudden realization. I can’t let this small problem affect my image. I woke up early today.
I found the time conversion function of sqlserver yesterday. There are many kinds of convert, but there is no format like 2009-11-01. I don’t know if it’s me or not.
There is no way but to neutralize it. First convert 2009-11-01 to 20091101 and then 11 30 2009 10:20:20AM or 2009-11-30 10:20:20.233 is converted into 20091130 and then compared.
Don’t mention it, there are really results
select * from table where convert(varchar(10), date_time,112) !< $begin_date and convert(varchar(10),date_time,112) !> $end_date
(!< and !> almost tripped me up too)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321001.htmlTechArticleLast Friday, I wanted to make a php connection to mysql database and sqlserver database at the same time. Dongdong has been using mysql before. I am not very familiar with sqlserver, so I am crossing the river by feeling the stones. Nothing else...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template