Label:
Today I find that it is not too long to read a blog post, as long as you can describe what you want to express, to let people know what you want to say. Because I read some long blog today, I really feel that there are too many knowledge points, it will make people swallowed.
This blog post is similar to the one I published yesterday to address a statistical requirement, and the result is a request to return the month from which the
Create a table by writing various SQL statements for mysql to obtain data for one day, one week, or one month:
Create table if not exists t(Id int,AddTime datetime default '2017-00-00 00:00:00 ′)
Add two initial data items:
Insert t values (1, '2017-07-12 21:00:00 ′);Insert t values (2, '2017-07-22 21:00:00 ′);
1. data inserted on the current or current day:
1. traditional comparison judgment: SELECT
SQL Lunar transformation function (display Chinese format, add run month display)
Create a lunar date functionIf object_id (' Fn_getlunar ') is not nullDrop function Fn_getlunarGoCreate function Dbo.fn_getlunar (@solarday datetime)Returns nvarchar (30)AsBeginDECLARE @soldata intDECLARE @offset intDECLARE @ilunar intDECLARE @i intDECLARE @j intDECLARE @ydays intD
The SQL statement is as follows:
Select Year = year (getdate (), month = month (getdate (), Day = Day (getdate ()), Hour = datepart (hour, getdate ()), Minute = datepart (minute, getdate ()), Second = datepart (second, getdate ())
Concatenate the system time into the year, month, day, hour, minute, and second.
Sel
first day of the quarter with a MySQL statement DateConcat (Year (Curdate ()), '-',if (Quarter (Curdate ()) =1,1,if (Quarter (Curdate ()) =2,4,if (Quarter (Curdate ()) =3,7,10)) Get the first day of the quarter with a MySQL statement:Optimization:DateConcat (Year (Curdate ()), '-', ELT (quarter (Curdate ()), 1,4,7,10), '-', 1)) The first day of the weekDate_add (Date (' 2009-5-29 '), Interval-weekday (' 2009-5-29 ') day) MySQL Gets the same day publi
Tags: Today select * FROM table name where To_days (Time field name) = To_days (now ()); Yesterday select * FROM table name where To_days (now ())-To_days (Time field name)
MSSQL gets yesterday, this week, this month ...Original link Address: http://blog.knowsky.com/186111.htm Special instructions under: The following statistics this week data, Sunday is as the first day of next week, not the last day of the week, so you put Sunday as th
SQL queries today's records:
Datediff (day, [datetime], getdate () = 0 replace datetime with your corresponding field;
SQL query records of yesterday:
Datediff (day, [datetime], getdate () = 1 replace datetime with your corresponding field. getdate ()-datetime is the time difference.
This month's record:
Select * from table where datediff (month, [datea
valueDate_value:=extract (Date_field from [Datetime_value|interval_value])Sql> Select Extract (month from sysdate) ' this month ' from dual;This Month----------11Sql> Select Extract (Y
Code code as follows:
SELECT * from ' article ' where To_days (now ()) –to_days (' Add_time ')
Inquire about the information records of the last 7 days:
Copy Code code as follows:
SELECT * from ' article ' where Date_sub (Curdate (), INTERVAL 7 day)
Inquire about the information records of the last 30 days:
Copy Code code as follows:
SELECT * from ' article ' where Date_sub (Curdate (), INTERVAL Day)
Check this month's information record
Tags: color ar data Art div sp on time line--按日 select sum(consume),day([date]) from consume_record where year([date]) = ‘2006‘ group by day([date]) --按周quarter select sum(consume),datename(week,[date]) from consume_record where year([date]) = ‘2006‘ group by datename(week,[
Tags: time div mon body where style MySQL serve created --according to MySQL grammar statistics by week, month, quarter, year. Income is the total Price field and CreateDate is the trading time.
Select sum(income) asRevenue,week (CreateDate) asWeekMonth(CreateDate) as Month, Quarter (CreateDate) asQuarter Year(CreateDate) as Year fromEmployeewhere Year(CreateDate)>= '2006' Group byWeek (createdate),
regions for the next year).(2) The rule in MySQL date and time type is to convert the two-digit year value in the date to four-bit. So for ' 1997-10-07 ' and ' 97-10-07 ' will be considered the same date:The code is as follows:Mysql> Select To_days (' 1997-10-07 '), To_days (' 97-10-07 ');--729669, 729669(2) Str_to_dateThis function can translate the string time completely, such as:The code is as follows:M
SQL statement truncation time, showing only the year, month, and day)
Select convert (varchar, getdate (), 120)
Change 'getdate () 'to the time field name 'createtime'Rename the new column (Select name as uname from Users)
For example, select convert (varchar (11), createtime, 120) as ndate from users
Select convert (varchar (10), your time column, 120) date, su
The first day of the quarter, and then you can convert the string to a date. There are many methods, including aliases (synonyms) for the same function. such as Curdate (), Current_date (), current_date, now, etc. can return to the same day
MySQL Tutorials > select Curdate (), ELT (Quarter (Curdate ()),-> year (Curdate ()) *1000+0101,-> year (Curdate ()) *1000+0401,-> year (Curdate ()) *1000+0701,-> year (Curdate ()) *1000+1001) as FIRSTDAYOFQ;+-----
|interval_value])Sql> Select Extract (month from sysdate) ' this month ' from dual;This Month----------11Sql> Select Extract (Year from add_months (sysdate,36)) ' 3 years out ' from dual;3 years out-----------2006Sql>6, Last_day (
The method previously found online isSelect Day (DateAdd(mm,1,getdate())-Day (getdate()))This method normally works, but in some months 31st errors occur, such as January 31, August 31, etc.Re-change the method, you can normally get the number of days in the monthSelect Day (dateadd(MONTH,1,GETDATE()-Day (GETDATE())+ 1)-1)Test comparisons can be made using the following statementsDeclare @date datetime=C
Java. util. Date: indicates the operation time:
Java. util. Date d1 = new java. util. Date (); // a time is created based on the current time.
Of course, you can also use another method: long times =System. currenttimemillis ();
Java. util. Date D2 = new date (times );
the week) [SQL]Select next_day (sysdate, 3) from dual; check the result:Why is this result? Because 1 represents Sunday, and 3 represents week 2.The system time has passed Tuesday, so it will represent Tuesday next week.6. Current_date (): returns the current date in the current session time zone [SQL]Alter session set time_zone = '-11: 00 ';Select sessiontimezo
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