Tags: http using data ar div time amp databaseMySQL query timestamp and date conversion in the use of the database, it is often necessary to query records by the specified date, in order to facilitate statistics, and in the database, there are many stored in the timestamp, but also some direct storage
century
MM:01~12 month number month
: Nine characters of the month, the right with a space to fill
MON: three-character month abbreviation
WW: Week of the Year D: Day of the week DD: Day of the
month DDD: Days of the
year
Day: Nine characters full name, right with space
Hh,hh12: The first hours of the day, 12 binary notation
HH24: The hour of the day, the value is~23
MI: Minutes in one hour
SS: Seconds
in one minute To_char (): Converts a date
Using the Date_format methodSELECT * from ' Ler_items ' WHERE date_format (posttime, '%y-%m ') = ' 2013-03 '
Note: The date must be used ', otherwise no effect
Some other about MySQL date lookup statements
Mysql> Select Date_format (Date_sub (Curdate (), INTERVAL 7 day), '%y%m%d ');
+ ——————————————————— –+
| Date_format (Date_sub (Curdate (), INTERVAL 7 day), '%y%m%d ' |
+ ——————————————————— –+
| 120416 |
SELECT * FROM table where to_days (dateline) = To_days (now ());SELECT * FROM table where date (dateline) = Curdate ();--Query yesterday recordsSELECT * FROM table where to_days (dateline) = To_days (now ())-1;SELECT * FROM table where date (dateline) = Curdate ()-1; --Today is the first day of the month to find the last day of the month record--
There is a forum to see a post, " Consult the query out of the continuous date record method", screenshot as follows:
Insus.net tries to write a program and test it to get the expected results, which can be referenced and learned by SQL code.
Copy Code code as follows:
--Create a temporary table that will store records for consecutive dates
CREATE TABLE #temp (IDD VARCHAR (), Sdate DA
Tag: Now ()--Current time int select extra format MySQL date form1 --query data for the whole day yesterday2 SELECTDate_format (Date_sub (now (), INTERVAL1 Day) ,'%y-%m-%d 00:00:00') as 'Yesterday start time', Date_format (Date_sub (now (), INTERVAL1 Day) ,'%y-%m-%d 23:59:59') as 'yesterday's End time' 3 --query data starting today to the current time4 SELECTDa
Date interval query for MyBatis
The first time the younger brother writes the blog to write casually
Such plug-ins must be used by all, but the types returned by these plug-ins are string, so I used to mybatis the string into date to query, which translated the steps of the dat
yearSelect Datename (WEEKDAY, ' 2016-8-31 ')--datepart is equivalent to Datename, the difference is that Datename returns a string, and DATEPART returns an int typeSelect DATEPART (WEEKDAY, ' 2016-8-31 ')--1 is Sunday, 7 is Saturday--Returns an integer that returns the year, month, and day of the dateSelect year (' 2016-8-31 ')Select month (' 2016-8-31 ')Select Day (' 2016-8-31 ')--Get local timeSelect GETDATE ()--No parameters required--Get the exact time of the systemSelect Sysdatetime ()--De
Label:Date number number of warehouses2012-05-31 C001 a shop 136.002012-05-29 C001 a shop 139.002012-05-29 C001 B Shop 5.002012-05-30 C001 B Shop 6.00I only show the maximum date of the record, how does this SQL write?ThatDate number number of warehouses2012-05-31 C001 a shop 136.002012-05-30 C001 B Shop 6.00
SQL Code
Select * FromTB Twhere not exists(select 1 from TB where number =T. number and warehouse =T. Warehous
));Querying data for the current weekSELECT name,submittime fromenterprise WHERE yearweek (date_format (submittime, '%y-%m-%d ')) = Yearweek (now ());Query last week's dataSELECT name,submittime fromenterprise WHERE yearweek (date_format (submittime, '%y-%m-%d ')) = Yearweek (now ())-1;Querying data for the previous monthSelect Name,submittime fromenterprise where Date_format (submittime, '%y-%m ') =date_format (Date_sub (Curdate (), INTERVAL 1 MONTH)
The most recent problems with Access databases are summarized:
The use of like in Access
Like wildcard usage in Access is this:
“?” Represents any single character; "*" means 0 or more characters; "#" means any number
So it should be:
SELECT * from DatabaseName where fieldname like ' *xx* '
But in SQL SERVER, 0 or more characters are represented in%
Ii. How to query the date range data fo
DAYSQHQL = "Select sum (c.casenum) from domain. Case C where "+ " convert (varchar ( -1,120), c.limitlastdate,120) = "+ " convert (varchar (), GETDATE ()) "; number of items received yesterdayCONVERT (varchar), c.limitlastdate,120 = convert (varchar), GETDATE ()-1,120);If you want to receive the number of yesterday, then you have to compare today minus the day after the date and the
Date-time formatted query in SQL statementsHow to use convert: Format: Convert (Data_type,expression[,style])Description: This style is typically used when the time type (Datetime,smalldatetime) and the string type (Nchar,nvarchar,char,varchar) are converted to each other.Example: Select Convert (varchar (+), GETDATE (), 101) NowThe result is: now = 09/15/2001The style numbers have the following meanings w
Simple string comparison results are imprecise.select*from表明wheretimes>‘2088/12/8 10:02:40‘(x)The conversion function is as follows (the database is varchar):select*fromh_hotelcontextwherenow()betweenSTR_TO_DATE(Start_time,‘%Y-%m-%d %H:%i:%s‘)andSTR_TO_DATE(End_time,‘%Y-%m-%d %H:%i:%s‘);selectmax(addtime)fromstudentwhere stuid=‘9‘;(×)selectmax(STR_TO_DATE(addtime,‘%Y/%m/%d %H:%i:%s‘))fromstudent wherestuid=‘9‘;MySQL database date is a varchar type of
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.