MySQL: Date function, time function processing

Source: Internet
Author: User

Date_add () Increase
MYSQL gets the current time plus one months

Update User set Leverstart=Now (), leverover=1MONTHwhere id=  1;

Date_sub () reduction

Date_sub ('1998-01-01 00:00:00'1 1:1:1' day_second)

Month months
minute min
Second SEC
Hour Hours
Week Week
Quarter Engraved
year
get current time: Now (); Sysdate ()
Get current timestamp function: Current_timestamp, Current_timestamp ()
Date/Time converted to String function: Date_format (Date,format), Time_format (Time,format)
string conversion To date function: Str_to_date (str, format)
date, day conversion function: To_days (date), From_days (days)
time, seconds conversion function: Time_to_sec (times), sec_to_time (seconds)

Select time_to_sec ('01:00:00'--  3600Select sec_to_ Time (3600--  ' 01:00:00 ' )

Patchwork date, Time function: Makdedate (year,dayofyear), Maketime (Hour,minute,second)

Select makedate (1901,+--  ' 1901-01-30 'select makedate (  1901,--  ' 2001-02-02 'select maketime (one, one,  - -- ' 11:35:30 '

Date, time subtraction function: DateDiff (DATE1,DATE2), Timediff (time1,time2)

Select DateDiff('2008-08-01','2008-08-08');---7SelectTimediff ('2008-08-08 08:08:08','2008-08-08 00:00:00');--08:08:08SelectTimediff ('08:08:08','00:00:00');--08:08:08

Timestamp (timestamp) conversion, increment, decrement function:
Timestamp (date)--date to timestamp
Timestamp (dt,time)--DT + Time
Timestampadd (unit,interval,datetime_expr)--

Timestampdiff (UNIT,DATETIME_EXPR1,DATETIME_EXPR2)--

Select timestamp('2008-08-08');--2008-08-08 00:00:00Select timestamp('2008-08-08 08:00:00','01:01:01');--2008-08-08 09:01:01Select timestamp('2008-08-08 08:00:00','Ten 01:01:01');--2008-08-18 09:01:01SelectTimestampadd ( Day,1,'2008-08-08 08:00:00');--2008-08-09 08:00:00SelectDate_add ('2008-08-08 08:00:00', Interval1  Day);--2008-08-09 08:00:00

Timestampadd () function

SelectTimestampdiff ( Year,'2002-05-01','2001-01-01');---1SelectTimestampdiff ( Day,'2002-05-01','2001-01-01');---485SelectTimestampdiff (Hour,'2008-08-08 12:00:00','2008-08-08 00:00:00');---12Select DateDiff('2008-08-08 12:00:00','2008-08-01 00:00:00');--7

The Timestampdiff () function is stronger than DATEDIFF (), and DateDiff () can only calculate the number of days between two dates (date).

MySQL: Date function, time function processing (RPM)

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.