Use TIMESTAMPDIFF to calculate the time difference between two dates in MySql:Syntax:TIMESTAMPDIFF (interval, datetime_expr1, datetime_expr2)Note:Returns the integer difference between datetime_expr1 and datetime_expr2the. The resultThe unit is
SUN provides a set of database access specifications (that is, a set of interfaces) and protocol standards for database connection, then various database manufacturers follow SUN's specifications to provide a set of APIs to access their own database
MySQL's time function bitsCN. comCURDATE () or CURRENT_DATE () returns the current date, in YYYY-MM-DD or YYYYMMDD format. Contains only the year, month, and day
select curdate()+0;Result: 20140214
select curdate()+1;Result: 20140215
CURTIME () or
For the description of the valid format of the value range of each type and the specified date and time value, see 7.3.6 Date and Time type.
Here is an example of using the date function. The following query Selects all records. The value of
Returns the week index of date (0 = Monday, 1 = Tuesday ,...... 6 = Sunday ). Mysql> select weekday ('2017-10-04 22:23:00 ');-> 5 mysql> select weekday ('2017-11-05');-> 2 dayofmonth (date) returns the date of a month in the range of 1 to 31. Mysql>
Because the XML string generated by calling the dataset built-in method getxml () in C # does not have the XMLSCHEMA ArchitectureIn the generated XML string, the time format is"2009-07-07t14: 58: 27 + 08: 00 "stored
If there is no comment on the
In the LAMP environment, it is ideal that the time zones of Linux PHP MySQL are set to the same. Otherwise, the program will easily encounter time difference problems. Assume that the time zone is set to "Asia/Shanghai"1. Set the time zone in Linux.
I. Basic Introduction1. to_days (date)Returns the number of days (the number of days from 0 years ):Mysql> select to_days (20110311 );+ ------------------- +| To_days (20110311) |+ ------------------- +| 1, 734572 |+ ------------------- +1 row in
Calculate the number of yearsIf you want to calculate the age of the person by birth, you can use the following statement:
SELECT Date_format (From_days to_days (now ())-To_days (@dateofbirth)), '%Y ') + 0;
2. Two difference in timeGets the
1 Get current date + time (date + times) 1.1 function: Now ()
Related functions: Current_timestamp (), localtime (), Localtimestamp ()
2. Get Current date
Function: Curdate ()
Related functions: Current_date (), current_date
3. Get current time
Unix_timestamp "2009-09-15 00:00:00" converted to a function classified as a long integer typeSelect unix_timestamp("2013-03-15 00:00:00") *1000, it is important to note that the long integer in the MySQL database is less than the number of
1 now ()//Current Time 2 sysdate ()//Current time 3 Current_timestamp 4 returns the current date and time in ' Yyyy-mm-dd HH:MM:SS ' or YYYYMMDDHHMMSS format, Depends on whether the function is used in a string or in the context of a number. 5 mysql>
Today the project table needs to import several w data, but the date is two one is the standard time a timestamp, the program search is based on time stamp to search, so in the online rummaging finally find the solution, using Excel to convert
User_event: User Event tableCreate_time: A field that stores time in a table#获取当月数据SELECT * fromUser_eventWHEREDate_format (Create_time,'%y-%m')=Date_format (now (),'%y-%m') #获取3月份数据SELECT * fromUser_eventWHEREDate_format
Calculation yearsIf you want to calculate the person's age by birthday, you can use the following statement:
SELECT DATE_FORMAT (FROM_DAYS (TO_DAYS (now ()-TO_DAYS (@ dateofbirth), '% y') + 0;
2. Difference between two time pointsReturns
SameDisplay
The display format of the TIMESTAMP column is the same as that of the DATETIME column. In other words, the display width is fixed to 19 characters and the format is YYYY-MM-DD HH: MM: SS.
Different
Range
Datetime retrieves and displays
Format
Description
%
Abbreviated name of a week
% B
Abbreviated month name
% C
Month, Value
% D
Day of the month with an English prefix
% D
Day of the month, numeric value (00-31)
Here is an example of using the date function. The following query Selects all records. The value of date_col is within the last 30 days:
Mysql> select something from tableWhere to_days (now ()-to_days (date_col)
Dayofweek (date)Returns the
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.