current_date()는 현재 시간의 날짜만 표시합니다
例如: select current_date() from a ; 结果:2021-08-25
current_time()은 현재 시간의 시, 분, 초만 표시합니다
例如: select CURRENT_TIME() from a ; 14:07:06
now()는 모두 표시
例如: select now() from a ; 结果:2021-08-25 14:07:56
날짜를 늘리거나 줄일 때 current_time , current_date()는 now()와 유사합니다. 차이점은 다음과 같습니다. CURRENT_DATE() function
#获取当前日期 SELECT CURRENT_DATE() AS newDate; #2021-05-20 #当前日期加1天(其他天数方法一样) SELECT DATE_ADD(CURRENT_DATE(), INTERVAL 1 DAY) AS newDate; #2021-05-21 #当前日期减1天 SELECT DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY) AS newDate; #2021-05-19 #当前日期加1个月 SELECT DATE_ADD(CURRENT_DATE(), INTERVAL 1 MONTH) AS newDate; #2021-06-20 #当前日期减1个月 SELECT DATE_ADD(CURRENT_DATE(), INTERVAL -1 MONTH) AS newDate; #2021-04-20 #当前日期加1年 SELECT DATE_ADD(CURRENT_DATE(), INTERVAL 1 YEAR) AS newDate; #2022-05-20 #当前日期减1年 SELECT DATE_ADD(CURRENT_DATE(), INTERVAL -1 YEAR) AS newDate; #2020-05-20 #指定日期加1天(可将DAY换为MONTH,YEAR来实现加1个月,1年) SELECT DATE_ADD('2021-05-20', INTERVAL 1 DAY) AS newDate; #2021-05-21 #指定日期减1天(可将DAY换为MONTH,YEAR来实现减1个月,1年) SELECT DATE_ADD('2021-05-20', INTERVAL -1 DAY) AS newDate; #2021-05-19 #当前时间添加1小时10分钟10秒钟 SELECT DATE_ADD(NOW(), INTERVAL '1:10:10' HOUR_SECOND) AS newTime; #2021-05-20 15:59:32 #指定时间添加1小时10分钟10秒钟 SELECT DATE_ADD('2019-04-17 2:00:00', INTERVAL '1:10:10' HOUR_SECOND) AS newTime; #2021-04-17 03:10:10
NOW() function
#获取当前时间 SELECT NOW() AS newTime; #2021-05-20 14:28:41 #当前时间减30秒 SELECT (NOW() - INTERVAL 30 SECOND) AS newTime; #2021-05-20 14:29:31 #当前时间加30秒 SELECT (NOW() + INTERVAL 30 SECOND) AS newTime; #2021-05-20 14:29:31 #当前时间减30分钟 SELECT (NOW() - INTERVAL 30 MINUTE) AS newTime; #2021-05-20 14:02:26 #当前时间加30分钟 SELECT (NOW() + INTERVAL 30 MINUTE) AS newTime; #2021-05-20 15:02:41 #当前时间减1天 SELECT (NOW() - INTERVAL 1 DAY) AS newTime; #2021-05-19 14:33:26 #当前时间加1天 SELECT (NOW() + INTERVAL 1 DAY) AS newTime; #2021-05-21 14:33:33 #当前时间减1个月 SELECT (NOW() - INTERVAL 1 MONTH) AS newTime; #2021-04-20 14:34:10 #当前时间加1个月 SELECT (NOW() + INTERVAL 1 MONTH) AS newTime; #2021-06-20 14:34:47 #当前时间减1年 SELECT (NOW() - INTERVAL 1 YEAR) AS newTime; #2020-05-20 14:35:09 #当前时间加1年 SELECT (NOW() + INTERVAL 1 MONTH) AS newTime; #2022-05-20 14:35:23 #指定时间的加减,将上面的NOW()函数换为指定日期时间即可,以加30分钟为例,如下: SELECT ('2021-05-20 12:30:00' + INTERVAL 30 MINUTE) AS newTime; #2021-05-20 13:00:00
위 내용은 MySQL에서 current_time/current_date()와 now()의 차이점은 무엇입니까의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!