sqlserver2005 tutorial PHP operation sqlserver small insights on time and date reading

WBOY
Release: 2016-07-29 08:41:16
Original
1054 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 still relatives
When doing conditional queries. A problem occurred
Firstly, the time queried was 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
I checked later 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
If it is under mysql
For example, I want to find the time in 2009 -Data from the time period from 11-01 to 2009-11-30
select * from table where time > '2009-11-01' and time < '2009-11-30';
I drew a tiger, As a result, I don’t know where my where went, and it has no effect.
I think my 2009-11-01 is really not easy to follow 11 30 2009 10:20:20AM or 2009-11-30 10:20:20.233 Comparison, at least the comparability is not big
So I converted my 2009-11-01 to 11 01 2009 00:00:00AM and 2009-11-01 00:00:00.000
Another comparison will not work. An error occurred at ":". Isn’t this uncomfortable?
So I searched awkwardly for a whole day without any realization. I can’t let this small problem affect my image. I woke up early today.
Yesterday I found the time conversion function convert of sqlserver, which includes many kinds. , there is no such format as 2009-11-01, and I don’t know if I am stupid 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)
The above introduces the sqlserver2005 tutorial PHP operation sqlserver's small insights on time and date reading, including the content of the sqlserver2005 tutorial. I hope it will be helpful to friends who are interested in the PHP tutorial.

Related labels:
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