now (); Current specific date and time

curdate (); current date

curtime(); current time

<>1.MySQL Add or subtract a time interval

Set current date variable

set @dt = now(); // Set current date

select @dt; // Query variable value

Add or subtract a time interval function date_add() And date_sub()

date_add(‘ A date and time ’,interval 1 Time category name );

Example :

select date_add(@dt, interval 1 year); // plus 1 year
select date_add(@dt, interval 1 month); // plus 1 month

quarter: season ,week: week ,day: day ,hour: hour ,minute: minute ,second: second ,microsecond: millisecond

notes : Variables can also be omitted , Add or subtract a time directly , as :select date_add(‘1998-01-01’, interval 1 day);

<>2. Subtract dates

datediff(date1,date2): Subtract two dates ,date1 subtract date2 Get the number of days after subtraction

timediff(time1,time2): Subtract two times time1 reduce time2, Return difference .

select timediff(‘2019-06-0312:30:00’, ‘2019-06-0312:29:30’);

Equivalent to

select timediff(‘12:30:00’, ‘12:29:30’);

Technology
©2019-2020 Toolsou All rights reserved,
Solve in servlet The Chinese output in is a question mark C String function and character function in language MySQL management 35 A small coup optimization Java performance —— Concise article Seven sorting algorithms (java code ) use Ansible Batch deployment SSH Password free login to remote host according to excel generate create Build table SQL sentence Spring Source code series ( sixteen )Spring merge BeanDefinition Principle of Virtual machine installation Linux course What are the common exception classes ?