content_image/820725.jpg content_image/820741.jpg
mysql> SHOW WARNINGS\G *************************** 1. row *************************** Level: Warning Code: 1411 Message: Incorrect datetime value: ’00/00/0000’ for function str_to_date 

<img src='content_image/820725.jpg'>

## • SUBDATE( date ,INTERVAL expr unit ) , SUBDATE( expr , days ) 

## Note 

You cannot use format "%X%V"  to convert a year-week string to a date because the combination of a year and week does not uniquely identify a year and month if the week crosses a month boundary. To convert a year-week to a date, you should also specify the weekday: 

mysql> SELECT STR_TO_DATE(’200442 Monday’, ’%X%V %W’); -> ’2004-10-18’ 

Date and Time Functions 

When invoked with the INTERVAL  form of the second argument, SUBDATE()  is a synonym for DATE_SUB() . For information on the INTERVAL unit  argument, see the discussion for DATE_ADD() . 

mysql> SELECT DATE_SUB(’2008-01-02’, INTERVAL 31 DAY); -> ’2007-12-02’ mysql> SELECT SUBDATE(’2008-01-02’, INTERVAL 31 DAY); -> ’2007-12-02’ 

The second form enables the use of an integer value for days . In such cases, it is interpreted as the number of days to be subtracted from the date or datetime expression expr . 

mysql> SELECT SUBDATE(’2008-01-02 12:00:00’, 31); -> ’2007-12-02 12:00:00’ 

## • SUBTIME( expr1 , expr2 ) 

SUBTIME()  returns expr1 − expr2  expressed as a value in the same format as expr1 . expr1  is a time or datetime expression, and expr2  is a time expression. 

mysql> SELECT SUBTIME(’2007-12-31 23:59:59.999999’,’1 1:1:1.000002’); -> ’2007-12-30 22:58:58.999997’ mysql> SELECT SUBTIME(’01:00:00.999999’, ’02:00:00.999998’); -> ’-00:59:59.999999’ 

## • SYSDATE([ fsp ]) 

Returns the current date and time as a value in ’ YYYY-MM-DD hh:mm:ss ’  or YYYYMMDDhhmmss format, depending on whether the function is used in string or numeric context. 

If the fsp  argument is given to specify a fractional seconds precision from 0 to 6, the return value includes a fractional seconds part of that many digits. 

SYSDATE()  returns the time at which it executes. This differs from the behavior for NOW() , which returns a constant time that indicates the time at which the statement began to execute. (Within a stored function or trigger, NOW()  returns the time at which the function or triggering statement began to execute.) 

mysql> SELECT NOW(), SLEEP(2), NOW(); 

<img src='content_image/820741.jpg'>

mysql> SELECT SYSDATE(), SLEEP(2), SYSDATE(); 

