<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="date-and-time-functions">
      </a>
      14.7 Date and Time Functions
     </h2>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045205615744">
  </a>
  <a class="indexterm" name="idm46045205614672">
  </a>
  <p>
   This section describes the functions that can be used to
      manipulate temporal values. See
   <a class="xref" href="date-and-time-types.html" title="13.2 Date and Time Data Types">
    Section 13.2, “Date and Time Data Types”
   </a>
   , for a description of the
      range of values each date and time type has and the valid formats
      in which values may be specified.
  </p>
  <div class="table">
   <a name="idm46045205611840">
   </a>
   <p class="title">
    <b>
     Table 14.11 Date and Time Functions
    </b>
   </p>
   <div class="table-contents">
    <table frame="box" rules="all" summary="A reference that lists date and time functions.">
     <colgroup>
      <col style="width: 28%"/>
      <col style="width: 71%"/>
     </colgroup>
     <thead>
      <tr>
       <th>
        Name
       </th>
       <th>
        Description
       </th>
      </tr>
     </thead>
     <tbody>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_adddate">
         <code class="literal">
          ADDDATE()
         </code>
        </a>
       </td>
       <td>
        Add time values (intervals) to a date value
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_addtime">
         <code class="literal">
          ADDTIME()
         </code>
        </a>
       </td>
       <td>
        Add time
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_convert-tz">
         <code class="literal">
          CONVERT_TZ()
         </code>
        </a>
       </td>
       <td>
        Convert from one time zone to another
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_curdate">
         <code class="literal">
          CURDATE()
         </code>
        </a>
       </td>
       <td>
        Return the current date
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_current-date">
         <code class="literal">
          CURRENT_DATE()
         </code>
         ,
         <code class="literal">
          CURRENT_DATE
         </code>
        </a>
       </td>
       <td>
        Synonyms for CURDATE()
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_current-time">
         <code class="literal">
          CURRENT_TIME()
         </code>
         ,
         <code class="literal">
          CURRENT_TIME
         </code>
        </a>
       </td>
       <td>
        Synonyms for CURTIME()
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_current-timestamp">
         <code class="literal">
          CURRENT_TIMESTAMP()
         </code>
         ,
         <code class="literal">
          CURRENT_TIMESTAMP
         </code>
        </a>
       </td>
       <td>
        Synonyms for NOW()
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_curtime">
         <code class="literal">
          CURTIME()
         </code>
        </a>
       </td>
       <td>
        Return the current time
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_date">
         <code class="literal">
          DATE()
         </code>
        </a>
       </td>
       <td>
        Extract the date part of a date or datetime expression
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_date-add">
         <code class="literal">
          DATE_ADD()
         </code>
        </a>
       </td>
       <td>
        Add time values (intervals) to a date value
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_date-format">
         <code class="literal">
          DATE_FORMAT()
         </code>
        </a>
       </td>
       <td>
        Format date as specified
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_date-sub">
         <code class="literal">
          DATE_SUB()
         </code>
        </a>
       </td>
       <td>
        Subtract a time value (interval) from a date
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_datediff">
         <code class="literal">
          DATEDIFF()
         </code>
        </a>
       </td>
       <td>
        Subtract two dates
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_day">
         <code class="literal">
          DAY()
         </code>
        </a>
       </td>
       <td>
        Synonym for DAYOFMONTH()
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_dayname">
         <code class="literal">
          DAYNAME()
         </code>
        </a>
       </td>
       <td>
        Return the name of the weekday
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_dayofmonth">
         <code class="literal">
          DAYOFMONTH()
         </code>
        </a>
       </td>
       <td>
        Return the day of the month (0-31)
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_dayofweek">
         <code class="literal">
          DAYOFWEEK()
         </code>
        </a>
       </td>
       <td>
        Return the weekday index of the argument
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_dayofyear">
         <code class="literal">
          DAYOFYEAR()
         </code>
        </a>
       </td>
       <td>
        Return the day of the year (1-366)
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_extract">
         <code class="literal">
          EXTRACT()
         </code>
        </a>
       </td>
       <td>
        Extract part of a date
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_from-days">
         <code class="literal">
          FROM_DAYS()
         </code>
        </a>
       </td>
       <td>
        Convert a day number to a date
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_from-unixtime">
         <code class="literal">
          FROM_UNIXTIME()
         </code>
        </a>
       </td>
       <td>
        Format Unix timestamp as a date
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_get-format">
         <code class="literal">
          GET_FORMAT()
         </code>
        </a>
       </td>
       <td>
        Return a date format string
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_hour">
         <code class="literal">
          HOUR()
         </code>
        </a>
       </td>
       <td>
        Extract the hour
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_last-day">
         <code class="literal">
          LAST_DAY
         </code>
        </a>
       </td>
       <td>
        Return the last day of the month for the argument
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_localtime">
         <code class="literal">
          LOCALTIME()
         </code>
         ,
         <code class="literal">
          LOCALTIME
         </code>
        </a>
       </td>
       <td>
        Synonym for NOW()
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_localtimestamp">
         <code class="literal">
          LOCALTIMESTAMP
         </code>
         ,
         <code class="literal">
          LOCALTIMESTAMP()
         </code>
        </a>
       </td>
       <td>
        Synonym for NOW()
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_makedate">
         <code class="literal">
          MAKEDATE()
         </code>
        </a>
       </td>
       <td>
        Create a date from the year and day of year
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_maketime">
         <code class="literal">
          MAKETIME()
         </code>
        </a>
       </td>
       <td>
        Create time from hour, minute, second
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_microsecond">
         <code class="literal">
          MICROSECOND()
         </code>
        </a>
       </td>
       <td>
        Return the microseconds from argument
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_minute">
         <code class="literal">
          MINUTE()
         </code>
        </a>
       </td>
       <td>
        Return the minute from the argument
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_month">
         <code class="literal">
          MONTH()
         </code>
        </a>
       </td>
       <td>
        Return the month from the date passed
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_monthname">
         <code class="literal">
          MONTHNAME()
         </code>
        </a>
       </td>
       <td>
        Return the name of the month
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_now">
         <code class="literal">
          NOW()
         </code>
        </a>
       </td>
       <td>
        Return the current date and time
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_period-add">
         <code class="literal">
          PERIOD_ADD()
         </code>
        </a>
       </td>
       <td>
        Add a period to a year-month
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_period-diff">
         <code class="literal">
          PERIOD_DIFF()
         </code>
        </a>
       </td>
       <td>
        Return the number of months between periods
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_quarter">
         <code class="literal">
          QUARTER()
         </code>
        </a>
       </td>
       <td>
        Return the quarter from a date argument
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_sec-to-time">
         <code class="literal">
          SEC_TO_TIME()
         </code>
        </a>
       </td>
       <td>
        Converts seconds to 'hh:mm:ss' format
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_second">
         <code class="literal">
          SECOND()
         </code>
        </a>
       </td>
       <td>
        Return the second (0-59)
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_str-to-date">
         <code class="literal">
          STR_TO_DATE()
         </code>
        </a>
       </td>
       <td>
        Convert a string to a date
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_subdate">
         <code class="literal">
          SUBDATE()
         </code>
        </a>
       </td>
       <td>
        Synonym for DATE_SUB() when invoked with three arguments
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_subtime">
         <code class="literal">
          SUBTIME()
         </code>
        </a>
       </td>
       <td>
        Subtract times
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_sysdate">
         <code class="literal">
          SYSDATE()
         </code>
        </a>
       </td>
       <td>
        Return the time at which the function executes
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_time">
         <code class="literal">
          TIME()
         </code>
        </a>
       </td>
       <td>
        Extract the time portion of the expression passed
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_time-format">
         <code class="literal">
          TIME_FORMAT()
         </code>
        </a>
       </td>
       <td>
        Format as time
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_time-to-sec">
         <code class="literal">
          TIME_TO_SEC()
         </code>
        </a>
       </td>
       <td>
        Return the argument converted to seconds
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_timediff">
         <code class="literal">
          TIMEDIFF()
         </code>
        </a>
       </td>
       <td>
        Subtract time
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_timestamp">
         <code class="literal">
          TIMESTAMP()
         </code>
        </a>
       </td>
       <td>
        With a single argument, this function returns the date or datetime
      expression; with two arguments, the sum of the arguments
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_timestampadd">
         <code class="literal">
          TIMESTAMPADD()
         </code>
        </a>
       </td>
       <td>
        Add an interval to a datetime expression
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_timestampdiff">
         <code class="literal">
          TIMESTAMPDIFF()
         </code>
        </a>
       </td>
       <td>
        Return the difference of two datetime expressions, using the units
      specified
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_to-days">
         <code class="literal">
          TO_DAYS()
         </code>
        </a>
       </td>
       <td>
        Return the date argument converted to days
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_to-seconds">
         <code class="literal">
          TO_SECONDS()
         </code>
        </a>
       </td>
       <td>
        Return the date or datetime argument converted to seconds since
      Year 0
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_unix-timestamp">
         <code class="literal">
          UNIX_TIMESTAMP()
         </code>
        </a>
       </td>
       <td>
        Return a Unix timestamp
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_utc-date">
         <code class="literal">
          UTC_DATE()
         </code>
        </a>
       </td>
       <td>
        Return the current UTC date
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_utc-time">
         <code class="literal">
          UTC_TIME()
         </code>
        </a>
       </td>
       <td>
        Return the current UTC time
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_utc-timestamp">
         <code class="literal">
          UTC_TIMESTAMP()
         </code>
        </a>
       </td>
       <td>
        Return the current UTC date and time
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_week">
         <code class="literal">
          WEEK()
         </code>
        </a>
       </td>
       <td>
        Return the week number
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_weekday">
         <code class="literal">
          WEEKDAY()
         </code>
        </a>
       </td>
       <td>
        Return the weekday index
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_weekofyear">
         <code class="literal">
          WEEKOFYEAR()
         </code>
        </a>
       </td>
       <td>
        Return the calendar week of the date (1-53)
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_year">
         <code class="literal">
          YEAR()
         </code>
        </a>
       </td>
       <td>
        Return the year
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="date-and-time-functions.html#function_yearweek">
         <code class="literal">
          YEARWEEK()
         </code>
        </a>
       </td>
       <td>
        Return the year and week
       </td>
      </tr>
     </tbody>
    </table>
   </div>
   <div class="table-contents">
    <table cellpadding="0" cellspacing="0" style="position: fixed; top: 0px; display: none; left: 401px; width: 739px;">
     <thead>
      <tr>
       <th style="width: 208.719px;">
        Name
       </th>
       <th style="width: 529.281px;">
        Description
       </th>
      </tr>
     </thead>
    </table>
   </div>
  </div>
  <br class="table-break"/>
  <p>
   Here is an example that uses date functions. The following query
      selects all rows with a
   <em class="replaceable">
    <code>
     date_col
    </code>
   </em>
   value
      from within the last 30 days:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa63540858"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <em class="replaceable">something</em> <span class="token keyword">FROM</span> <em class="replaceable">tbl_name</em>
<span class="token prompt">    -&gt;</span> <span class="token keyword">WHERE</span> <span class="token function">DATE_SUB</span><span class="token punctuation">(</span><span class="token function">CURDATE</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token keyword">INTERVAL</span> <span class="token number">30</span> <span class="token keyword">DAY</span><span class="token punctuation">)</span> <span class="token operator">&lt;=</span> <em class="replaceable">date_col</em><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   The query also selects rows with dates that lie in the future.
  </p>
  <p>
   Functions that expect date values usually accept datetime values
      and ignore the time part. Functions that expect time values
      usually accept datetime values and ignore the date part.
  </p>
  <p>
   Functions that return the current date or time each are evaluated
      only once per query at the start of query execution. This means
      that multiple references to a function such as
   <a class="link" href="date-and-time-functions.html#function_now">
    <code class="literal">
     NOW()
    </code>
   </a>
   within a single query always
      produce the same result. (For our purposes, a single query also
      includes a call to a stored program (stored routine, trigger, or
      event) and all subprograms called by that program.) This principle
      also applies to
   <a class="link" href="date-and-time-functions.html#function_curdate">
    <code class="literal">
     CURDATE()
    </code>
   </a>
   ,
   <a class="link" href="date-and-time-functions.html#function_curtime">
    <code class="literal">
     CURTIME()
    </code>
   </a>
   ,
   <a class="link" href="date-and-time-functions.html#function_utc-date">
    <code class="literal">
     UTC_DATE()
    </code>
   </a>
   ,
   <a class="link" href="date-and-time-functions.html#function_utc-time">
    <code class="literal">
     UTC_TIME()
    </code>
   </a>
   ,
   <a class="link" href="date-and-time-functions.html#function_utc-timestamp">
    <code class="literal">
     UTC_TIMESTAMP()
    </code>
   </a>
   , and to any of
      their synonyms.
  </p>
  <p>
   The
   <a class="link" href="date-and-time-functions.html#function_current-timestamp">
    <code class="literal">
     CURRENT_TIMESTAMP()
    </code>
   </a>
   ,
   <a class="link" href="date-and-time-functions.html#function_current-time">
    <code class="literal">
     CURRENT_TIME()
    </code>
   </a>
   ,
   <a class="link" href="date-and-time-functions.html#function_current-date">
    <code class="literal">
     CURRENT_DATE()
    </code>
   </a>
   , and
   <a class="link" href="date-and-time-functions.html#function_from-unixtime">
    <code class="literal">
     FROM_UNIXTIME()
    </code>
   </a>
   functions return
      values in the current session time zone, which is available as the
      session value of the
   <a class="link" href="server-system-variables.html#sysvar_time_zone">
    <code class="literal">
     time_zone
    </code>
   </a>
   system variable. In addition,
   <a class="link" href="date-and-time-functions.html#function_unix-timestamp">
    <code class="literal">
     UNIX_TIMESTAMP()
    </code>
   </a>
   assumes that its
      argument is a datetime value in the session time zone. See
   <a class="xref" href="time-zone-support.html" title="7.1.15 MySQL Server Time Zone Support">
    Section 7.1.15, “MySQL Server Time Zone Support”
   </a>
   .
  </p>
  <p>
   Some date functions can be used with
   <span class="quote">
    “
    <span class="quote">
     zero
    </span>
    ”
   </span>
   dates or
      incomplete dates such as
   <code class="literal">
    '2001-11-00'
   </code>
   , whereas
      others cannot. Functions that extract parts of dates typically
      work with incomplete dates and thus can return 0 when you might
      otherwise expect a nonzero value. For example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa47097457"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DAYOFMONTH</span><span class="token punctuation">(</span><span class="token string">'2001-11-00'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">MONTH</span><span class="token punctuation">(</span><span class="token string">'2005-00-00'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span></code></pre>
  </div>
  <p>
   Other functions expect complete dates and return
   <code class="literal">
    NULL
   </code>
   for incomplete dates. These include
      functions that perform date arithmetic or that map parts of dates
      to names. For example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa54626338"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2006-05-00'</span><span class="token punctuation">,</span><span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">DAY</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token boolean">NULL</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DAYNAME</span><span class="token punctuation">(</span><span class="token string">'2006-05-00'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token boolean">NULL</span></code></pre>
  </div>
  <p>
   Several functions are strict when passed a
   <a class="link" href="date-and-time-functions.html#function_date">
    <code class="literal">
     DATE()
    </code>
   </a>
   function value as their
      argument and reject incomplete dates with a day part of zero:
   <a class="link" href="date-and-time-functions.html#function_convert-tz">
    <code class="literal">
     CONVERT_TZ()
    </code>
   </a>
   ,
   <a class="link" href="date-and-time-functions.html#function_date-add">
    <code class="literal">
     DATE_ADD()
    </code>
   </a>
   ,
   <a class="link" href="date-and-time-functions.html#function_date-sub">
    <code class="literal">
     DATE_SUB()
    </code>
   </a>
   ,
   <a class="link" href="date-and-time-functions.html#function_dayofyear">
    <code class="literal">
     DAYOFYEAR()
    </code>
   </a>
   ,
   <a class="link" href="date-and-time-functions.html#function_timestampdiff">
    <code class="literal">
     TIMESTAMPDIFF()
    </code>
   </a>
   ,
   <a class="link" href="date-and-time-functions.html#function_to-days">
    <code class="literal">
     TO_DAYS()
    </code>
   </a>
   ,
   <a class="link" href="date-and-time-functions.html#function_to-seconds">
    <code class="literal">
     TO_SECONDS()
    </code>
   </a>
   ,
   <a class="link" href="date-and-time-functions.html#function_week">
    <code class="literal">
     WEEK()
    </code>
   </a>
   ,
   <a class="link" href="date-and-time-functions.html#function_weekday">
    <code class="literal">
     WEEKDAY()
    </code>
   </a>
   ,
   <a class="link" href="date-and-time-functions.html#function_weekofyear">
    <code class="literal">
     WEEKOFYEAR()
    </code>
   </a>
   ,
   <a class="link" href="date-and-time-functions.html#function_yearweek">
    <code class="literal">
     YEARWEEK()
    </code>
   </a>
   .
  </p>
  <p>
   Fractional seconds for
   <code class="literal">
    TIME
   </code>
   ,
   <code class="literal">
    DATETIME
   </code>
   , and
   <code class="literal">
    TIMESTAMP
   </code>
   values are supported, with up to microsecond precision. Functions
      that take temporal arguments accept values with fractional
      seconds. Return values from temporal functions include fractional
      seconds as appropriate.
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <a name="function_adddate">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_adddate">
       <code class="literal">
        ADDDATE(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        ,INTERVAL
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        <em class="replaceable">
         <code>
          unit
         </code>
        </em>
        )
       </code>
      </a>
      ,
      <a class="link" href="date-and-time-functions.html#function_adddate">
       <code class="literal">
        ADDDATE(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          days
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045205367136">
     </a>
     <p>
      When invoked with the
      <code class="literal">
       INTERVAL
      </code>
      form of the
          second argument,
      <a class="link" href="date-and-time-functions.html#function_adddate">
       <code class="literal">
        ADDDATE()
       </code>
      </a>
      is a
          synonym for
      <a class="link" href="date-and-time-functions.html#function_date-add">
       <code class="literal">
        DATE_ADD()
       </code>
      </a>
      . The
          related function
      <a class="link" href="date-and-time-functions.html#function_subdate">
       <code class="literal">
        SUBDATE()
       </code>
      </a>
      is a
          synonym for
      <a class="link" href="date-and-time-functions.html#function_date-sub">
       <code class="literal">
        DATE_SUB()
       </code>
      </a>
      . For
          information on the
      <code class="literal">
       INTERVAL
      </code>
      <em class="replaceable">
       <code>
        unit
       </code>
      </em>
      argument, see
      <a class="xref" href="expressions.html#temporal-intervals" title="Temporal Intervals">
       Temporal Intervals
      </a>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa16233991"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2008-01-02'</span><span class="token punctuation">,</span> <span class="token keyword">INTERVAL</span> <span class="token number">31</span> <span class="token keyword">DAY</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2008-02-02'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ADDDATE</span><span class="token punctuation">(</span><span class="token string">'2008-01-02'</span><span class="token punctuation">,</span> <span class="token keyword">INTERVAL</span> <span class="token number">31</span> <span class="token keyword">DAY</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2008-02-02'</span></code></pre>
     </div>
     <p>
      When invoked with the
      <em class="replaceable">
       <code>
        days
       </code>
      </em>
      form of
          the second argument, MySQL treats it as an integer number of
          days to be added to
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa98363321"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ADDDATE</span><span class="token punctuation">(</span><span class="token string">'2008-01-02'</span><span class="token punctuation">,</span> <span class="token number">31</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2008-02-02'</span></code></pre>
     </div>
     <p>
      This function returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        days
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_addtime">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_addtime">
       <code class="literal">
        ADDTIME(
        <em class="replaceable">
         <code>
          expr1
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          expr2
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045205342208">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_addtime">
       <code class="literal">
        ADDTIME()
       </code>
      </a>
      adds
      <em class="replaceable">
       <code>
        expr2
       </code>
      </em>
      to
      <em class="replaceable">
       <code>
        expr1
       </code>
      </em>
      and returns the result.
      <em class="replaceable">
       <code>
        expr1
       </code>
      </em>
      is a time or datetime
          expression, and
      <em class="replaceable">
       <code>
        expr2
       </code>
      </em>
      is a time
          expression. Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        expr1
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        expr2
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      The return type of this function and of the
      <a class="link" href="date-and-time-functions.html#function_subtime">
       <code class="literal">
        SUBTIME()
       </code>
      </a>
      function is
          determined as follows:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         If the first argument is a dynamic parameter (such as in a
              prepared statement), the return type is
         <code class="literal">
          TIME
         </code>
         .
        </p>
       </li>
       <li class="listitem">
        <p>
         Otherwise, the resolved type of the function is derived
              from the resolved type of the first argument.
        </p>
       </li>
      </ul>
     </div>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa98791089"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ADDTIME</span><span class="token punctuation">(</span><span class="token string">'2007-12-31 23:59:59.999999'</span><span class="token punctuation">,</span> <span class="token string">'1 1:1:1.000002'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2008-01-02 01:01:01.000001'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ADDTIME</span><span class="token punctuation">(</span><span class="token string">'01:00:00.999999'</span><span class="token punctuation">,</span> <span class="token string">'02:00:00.999998'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'03:00:01.999997'</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_convert-tz">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_convert-tz">
       <code class="literal">
        CONVERT_TZ(
        <em class="replaceable">
         <code>
          dt
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          from_tz
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          to_tz
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045205320208">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_convert-tz">
       <code class="literal">
        CONVERT_TZ()
       </code>
      </a>
      converts a
          datetime value
      <em class="replaceable">
       <code>
        dt
       </code>
      </em>
      from the time
          zone given by
      <em class="replaceable">
       <code>
        from_tz
       </code>
      </em>
      to the time
          zone given by
      <em class="replaceable">
       <code>
        to_tz
       </code>
      </em>
      and returns the
          resulting value. Time zones are specified as described in
      <a class="xref" href="time-zone-support.html" title="7.1.15 MySQL Server Time Zone Support">
       Section 7.1.15, “MySQL Server Time Zone Support”
      </a>
      . This function returns
      <code class="literal">
       NULL
      </code>
      if any of the arguments are invalid,
          or if any of them are
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      On 32-bit platforms, the supported range of values for this
          function is the same as for the
      <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
       <code class="literal">
        TIMESTAMP
       </code>
      </a>
      type (see
      <a class="xref" href="date-and-time-type-syntax.html" title="13.2.1 Date and Time Data Type Syntax">
       Section 13.2.1, “Date and Time Data Type Syntax”
      </a>
      , for range
          information). On 64-bit platforms, the maximum supported value
          is
      <code class="literal">
       '3001-01-18 23:59:59.999999'
      </code>
      UTC.
     </p>
     <p>
      Regardless of platform or MySQL version, if the value falls
          out of the supported range when converted from
      <em class="replaceable">
       <code>
        from_tz
       </code>
      </em>
      to UTC, no conversion
          occurs.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa77285895"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">CONVERT_TZ</span><span class="token punctuation">(</span><span class="token string">'2004-01-01 12:00:00'</span><span class="token punctuation">,</span><span class="token string">'GMT'</span><span class="token punctuation">,</span><span class="token string">'MET'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2004-01-01 13:00:00'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">CONVERT_TZ</span><span class="token punctuation">(</span><span class="token string">'2004-01-01 12:00:00'</span><span class="token punctuation">,</span><span class="token string">'+00:00'</span><span class="token punctuation">,</span><span class="token string">'+10:00'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2004-01-01 22:00:00'</span></code></pre>
     </div>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       To use named time zones such as
       <code class="literal">
        'MET'
       </code>
       or
       <code class="literal">
        'Europe/Amsterdam'
       </code>
       , the time zone tables
            must be properly set up. For instructions, see
       <a class="xref" href="time-zone-support.html" title="7.1.15 MySQL Server Time Zone Support">
        Section 7.1.15, “MySQL Server Time Zone Support”
       </a>
       .
      </p>
     </div>
    </li>
    <li class="listitem">
     <a name="function_curdate">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_curdate">
       <code class="literal">
        CURDATE()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045205297360">
     </a>
     <p>
      Returns the current date as a value in
      <code class="literal">
       '
       <em class="replaceable">
        <code>
         YYYY-MM-DD
        </code>
       </em>
       '
      </code>
      or
      <em class="replaceable">
       <code>
        YYYYMMDD
       </code>
      </em>
      format, depending on
          whether the function is used in string or numeric context.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa47148947"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">CURDATE</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2008-06-13'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">CURDATE</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">20080613</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_current-date">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_current-date">
       <code class="literal">
        CURRENT_DATE
       </code>
      </a>
      ,
      <a class="link" href="date-and-time-functions.html#function_current-date">
       <code class="literal">
        CURRENT_DATE()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045205283984">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_current-date">
       <code class="literal">
        CURRENT_DATE
       </code>
      </a>
      and
      <a class="link" href="date-and-time-functions.html#function_current-date">
       <code class="literal">
        CURRENT_DATE()
       </code>
      </a>
      are synonyms for
      <a class="link" href="date-and-time-functions.html#function_curdate">
       <code class="literal">
        CURDATE()
       </code>
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_current-time">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_current-time">
       <code class="literal">
        CURRENT_TIME
       </code>
      </a>
      ,
      <a class="link" href="date-and-time-functions.html#function_current-time">
       <code class="literal">
        CURRENT_TIME([
        <em class="replaceable">
         <code>
          fsp
         </code>
        </em>
        ])
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045205271184">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_current-time">
       <code class="literal">
        CURRENT_TIME
       </code>
      </a>
      and
      <a class="link" href="date-and-time-functions.html#function_current-time">
       <code class="literal">
        CURRENT_TIME()
       </code>
      </a>
      are synonyms for
      <a class="link" href="date-and-time-functions.html#function_curtime">
       <code class="literal">
        CURTIME()
       </code>
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_current-timestamp">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_current-timestamp">
       <code class="literal">
        CURRENT_TIMESTAMP
       </code>
      </a>
      ,
      <a class="link" href="date-and-time-functions.html#function_current-timestamp">
       <code class="literal">
        CURRENT_TIMESTAMP([
        <em class="replaceable">
         <code>
          fsp
         </code>
        </em>
        ])
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045205258304">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_current-timestamp">
       <code class="literal">
        CURRENT_TIMESTAMP
       </code>
      </a>
      and
      <a class="link" href="date-and-time-functions.html#function_current-timestamp">
       <code class="literal">
        CURRENT_TIMESTAMP()
       </code>
      </a>
      are
          synonyms for
      <a class="link" href="date-and-time-functions.html#function_now">
       <code class="literal">
        NOW()
       </code>
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_curtime">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_curtime">
       <code class="literal">
        CURTIME([
        <em class="replaceable">
         <code>
          fsp
         </code>
        </em>
        ])
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045205246720">
     </a>
     <p>
      Returns the current time as a value in
      <em class="replaceable">
       <code>
        'hh:mm:ss'
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        hhmmss
       </code>
      </em>
      format, depending on whether
          the function is used in string or numeric context. The value
          is expressed in the session time zone.
     </p>
     <p>
      If the
      <em class="replaceable">
       <code>
        fsp
       </code>
      </em>
      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.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa99899176"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">CURTIME</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> CURTIME() <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 19:25:37  <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">CURTIME</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> CURTIME() <span class="token punctuation">+</span> 0 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>        192537 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">CURTIME</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> CURTIME(3)   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 19:25:37.840 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_date">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_date">
       <code class="literal">
        DATE(
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045205232720">
     </a>
     <p>
      Extracts the date part of the date or datetime expression
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      . Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa21734437"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE</span><span class="token punctuation">(</span><span class="token string">'2003-12-31 01:02:03'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2003-12-31'</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_datediff">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_datediff">
       <code class="literal">
        DATEDIFF(
        <em class="replaceable">
         <code>
          expr1
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          expr2
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045205219728">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_datediff">
       <code class="literal">
        DATEDIFF()
       </code>
      </a>
      returns
      <em class="replaceable">
       <code>
        expr1
       </code>
      </em>
      −
      <em class="replaceable">
       <code>
        expr2
       </code>
      </em>
      expressed as a value in days
          from one date to the other.
      <em class="replaceable">
       <code>
        expr1
       </code>
      </em>
      and
      <em class="replaceable">
       <code>
        expr2
       </code>
      </em>
      are date or date-and-time
          expressions. Only the date parts of the values are used in the
          calculation.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa7667195"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATEDIFF</span><span class="token punctuation">(</span><span class="token string">'2007-12-31 23:59:59'</span><span class="token punctuation">,</span><span class="token string">'2007-12-30'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">1</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATEDIFF</span><span class="token punctuation">(</span><span class="token string">'2010-11-30 23:59:59'</span><span class="token punctuation">,</span><span class="token string">'2010-12-31'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token operator">-</span><span class="token number">31</span></code></pre>
     </div>
     <p>
      This function returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        expr1
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        expr2
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_date-add">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_date-add">
       <code class="literal">
        DATE_ADD(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        ,INTERVAL
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        <em class="replaceable">
         <code>
          unit
         </code>
        </em>
        )
       </code>
      </a>
      ,
      <a class="link" href="date-and-time-functions.html#function_date-sub">
       <code class="literal">
        DATE_SUB(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        ,INTERVAL
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        <em class="replaceable">
         <code>
          unit
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045205199376">
     </a>
     <a class="indexterm" name="idm46045205198304">
     </a>
     <p>
      These functions perform date arithmetic. The
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      argument specifies the
          starting date or datetime value.
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      is an expression specifying
          the interval value to be added or subtracted from the starting
          date.
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      is evaluated as a
          string; it may start with a
      <code class="literal">
       -
      </code>
      for negative
          intervals.
      <em class="replaceable">
       <code>
        unit
       </code>
      </em>
      is a keyword
          indicating the units in which the expression should be
          interpreted.
     </p>
     <p>
      For more information about temporal interval syntax, including
          a full list of
      <em class="replaceable">
       <code>
        unit
       </code>
      </em>
      specifiers, the
          expected form of the
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      argument
          for each
      <em class="replaceable">
       <code>
        unit
       </code>
      </em>
      value, and rules for
          operand interpretation in temporal arithmetic, see
      <a class="xref" href="expressions.html#temporal-intervals" title="Temporal Intervals">
       Temporal Intervals
      </a>
      .
     </p>
     <p>
      The return value depends on the arguments:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         If
         <em class="replaceable">
          <code>
           date
          </code>
         </em>
         is
         <code class="literal">
          NULL
         </code>
         , the function returns
         <code class="literal">
          NULL
         </code>
         .
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
          <code class="literal">
           DATE
          </code>
         </a>
         if the
         <em class="replaceable">
          <code>
           date
          </code>
         </em>
         argument is a
         <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
          <code class="literal">
           DATE
          </code>
         </a>
         value and your
              calculations involve only
         <code class="literal">
          YEAR
         </code>
         ,
         <code class="literal">
          MONTH
         </code>
         , and
         <code class="literal">
          DAY
         </code>
         parts
              (that is, no time parts).
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="time.html" title="13.2.3 The TIME Type">
          <code class="literal">
           TIME
          </code>
         </a>
         if the
         <em class="replaceable">
          <code>
           date
          </code>
         </em>
         argument is a
         <code class="literal">
          TIME
         </code>
         value and the calculations involve
              only
         <code class="literal">
          HOURS
         </code>
         ,
         <code class="literal">
          MINUTES
         </code>
         ,
              and
         <code class="literal">
          SECONDS
         </code>
         parts (that is, no date
              parts).
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
          <code class="literal">
           DATETIME
          </code>
         </a>
         if the first
              argument is a
         <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
          <code class="literal">
           DATETIME
          </code>
         </a>
         (or
         <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
          <code class="literal">
           TIMESTAMP
          </code>
         </a>
         ) value, or if the
              first argument is a
         <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
          <code class="literal">
           DATE
          </code>
         </a>
         and the
         <em class="replaceable">
          <code>
           unit
          </code>
         </em>
         value uses
         <code class="literal">
          HOURS
         </code>
         ,
         <code class="literal">
          MINUTES
         </code>
         , or
         <code class="literal">
          SECONDS
         </code>
         , or if the first argument is of
              type
         <a class="link" href="time.html" title="13.2.3 The TIME Type">
          <code class="literal">
           TIME
          </code>
         </a>
         and the
         <em class="replaceable">
          <code>
           unit
          </code>
         </em>
         value uses
         <code class="literal">
          YEAR
         </code>
         ,
         <code class="literal">
          MONTH
         </code>
         , or
         <code class="literal">
          DAY
         </code>
         .
        </p>
       </li>
       <li class="listitem">
        <p>
         If the first argument is a dynamic parameter (for example,
              of a prepared statement), its resolved type is
         <code class="literal">
          DATE
         </code>
         if the second argument is an
              interval that contains some combination of
         <code class="literal">
          YEAR
         </code>
         ,
         <code class="literal">
          MONTH
         </code>
         , or
         <code class="literal">
          DAY
         </code>
         values only; otherwise, its type is
         <code class="literal">
          DATETIME
         </code>
         .
        </p>
       </li>
       <li class="listitem">
        <p>
         String otherwise (type
         <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
          <code class="literal">
           VARCHAR
          </code>
         </a>
         ).
        </p>
       </li>
      </ul>
     </div>
     <p>
      To ensure that the result is
      <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
       <code class="literal">
        DATETIME
       </code>
      </a>
      , you can use
      <a class="link" href="cast-functions.html#function_cast">
       <code class="literal">
        CAST()
       </code>
      </a>
      to convert the first
          argument to
      <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
       <code class="literal">
        DATETIME
       </code>
      </a>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa23168089"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2018-05-01'</span><span class="token punctuation">,</span><span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">DAY</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2018-05-02'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_SUB</span><span class="token punctuation">(</span><span class="token string">'2018-05-01'</span><span class="token punctuation">,</span><span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token datatype">YEAR</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2017-05-01'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2020-12-31 23:59:59'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>                 <span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">SECOND</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2021-01-01 00:00:00'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2018-12-31 23:59:59'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>                 <span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">DAY</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2019-01-01 23:59:59'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2100-12-31 23:59:59'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>                 <span class="token keyword">INTERVAL</span> <span class="token string">'1:1'</span> <span class="token keyword">MINUTE_SECOND</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2101-01-01 00:01:00'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_SUB</span><span class="token punctuation">(</span><span class="token string">'2025-01-01 00:00:00'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>                 <span class="token keyword">INTERVAL</span> <span class="token string">'1 1:1:1'</span> <span class="token keyword">DAY_SECOND</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2024-12-30 22:58:59'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'1900-01-01 00:00:00'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>                 <span class="token keyword">INTERVAL</span> <span class="token string">'-1 10'</span> <span class="token keyword">DAY_HOUR</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'1899-12-30 14:00:00'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_SUB</span><span class="token punctuation">(</span><span class="token string">'1998-01-02'</span><span class="token punctuation">,</span> <span class="token keyword">INTERVAL</span> <span class="token number">31</span> <span class="token keyword">DAY</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'1997-12-02'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'1992-12-31 23:59:59.000002'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>            <span class="token keyword">INTERVAL</span> <span class="token string">'1.999999'</span> <span class="token keyword">SECOND_MICROSECOND</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'1993-01-01 00:00:01.000001'</span></code></pre>
     </div>
     <p>
      When adding a
      <code class="literal">
       MONTH
      </code>
      interval to a
      <code class="literal">
       DATE
      </code>
      or
      <code class="literal">
       DATETIME
      </code>
      value,
          and the resulting date includes a day that does not exist in
          the given month, the day is adjusted to the last day of the
          month, as shown here:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa56989440"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2024-03-30'</span><span class="token punctuation">,</span> <span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">MONTH</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> d1<span class="token punctuation">,</span> 
     <span class="token operator">&gt;</span>        <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2024-03-31'</span><span class="token punctuation">,</span> <span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">MONTH</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> d2<span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> d1         <span class="token punctuation">|</span> d2         <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 2024<span class="token punctuation">-</span>04<span class="token punctuation">-</span>30 <span class="token punctuation">|</span> 2024<span class="token punctuation">-</span>04<span class="token punctuation">-</span>30 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">1 row in set (0.00 sec)</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_date-format">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_date-format">
       <code class="literal">
        DATE_FORMAT(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          format
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045205127808">
     </a>
     <p>
      Formats the
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      value according to
          the
      <em class="replaceable">
       <code>
        format
       </code>
      </em>
      string. If either
          argument is
      <code class="literal">
       NULL
      </code>
      , the function returns
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      The specifiers shown in the following table may be used in the
      <em class="replaceable">
       <code>
        format
       </code>
      </em>
      string. The
      <code class="literal">
       %
      </code>
      character is required before format
          specifier characters. The specifiers apply to other functions
          as well:
      <a class="link" href="date-and-time-functions.html#function_str-to-date">
       <code class="literal">
        STR_TO_DATE()
       </code>
      </a>
      ,
      <a class="link" href="date-and-time-functions.html#function_time-format">
       <code class="literal">
        TIME_FORMAT()
       </code>
      </a>
      ,
      <a class="link" href="date-and-time-functions.html#function_unix-timestamp">
       <code class="literal">
        UNIX_TIMESTAMP()
       </code>
      </a>
      .
     </p>
     <div class="informaltable">
      <table summary="Specifier characters for the DATE_FORMAT function that may be used in the format string and provides a description of each specifier character.">
       <colgroup>
        <col style="width: 20%"/>
        <col style="width: 70%"/>
       </colgroup>
       <thead>
        <tr>
         <th>
          Specifier
         </th>
         <th>
          Description
         </th>
        </tr>
       </thead>
       <tbody>
        <tr>
         <td>
          <code class="literal">
           %a
          </code>
         </td>
         <td>
          Abbreviated weekday name
                (
          <code class="literal">
           Sun
          </code>
          ..
          <code class="literal">
           Sat
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %b
          </code>
         </td>
         <td>
          Abbreviated month name (
          <code class="literal">
           Jan
          </code>
          ..
          <code class="literal">
           Dec
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %c
          </code>
         </td>
         <td>
          Month, numeric (
          <code class="literal">
           0
          </code>
          ..
          <code class="literal">
           12
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %D
          </code>
         </td>
         <td>
          Day of the month with English suffix (
          <code class="literal">
           0th
          </code>
          ,
          <code class="literal">
           1st
          </code>
          ,
          <code class="literal">
           2nd
          </code>
          ,
          <code class="literal">
           3rd
          </code>
          , …)
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %d
          </code>
         </td>
         <td>
          Day of the month, numeric (
          <code class="literal">
           00
          </code>
          ..
          <code class="literal">
           31
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %e
          </code>
         </td>
         <td>
          Day of the month, numeric (
          <code class="literal">
           0
          </code>
          ..
          <code class="literal">
           31
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %f
          </code>
         </td>
         <td>
          Microseconds (
          <code class="literal">
           000000
          </code>
          ..
          <code class="literal">
           999999
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %H
          </code>
         </td>
         <td>
          Hour (
          <code class="literal">
           00
          </code>
          ..
          <code class="literal">
           23
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %h
          </code>
         </td>
         <td>
          Hour (
          <code class="literal">
           01
          </code>
          ..
          <code class="literal">
           12
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %I
          </code>
         </td>
         <td>
          Hour (
          <code class="literal">
           01
          </code>
          ..
          <code class="literal">
           12
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %i
          </code>
         </td>
         <td>
          Minutes, numeric (
          <code class="literal">
           00
          </code>
          ..
          <code class="literal">
           59
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %j
          </code>
         </td>
         <td>
          Day of year (
          <code class="literal">
           001
          </code>
          ..
          <code class="literal">
           366
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %k
          </code>
         </td>
         <td>
          Hour (
          <code class="literal">
           0
          </code>
          ..
          <code class="literal">
           23
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %l
          </code>
         </td>
         <td>
          Hour (
          <code class="literal">
           1
          </code>
          ..
          <code class="literal">
           12
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %M
          </code>
         </td>
         <td>
          Month name (
          <code class="literal">
           January
          </code>
          ..
          <code class="literal">
           December
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %m
          </code>
         </td>
         <td>
          Month, numeric (
          <code class="literal">
           00
          </code>
          ..
          <code class="literal">
           12
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %p
          </code>
         </td>
         <td>
          <code class="literal">
           AM
          </code>
          or
          <code class="literal">
           PM
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %r
          </code>
         </td>
         <td>
          Time, 12-hour (
          <em class="replaceable">
           <code>
            hh:mm:ss
           </code>
          </em>
          followed by
          <code class="literal">
           AM
          </code>
          or
          <code class="literal">
           PM
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %S
          </code>
         </td>
         <td>
          Seconds (
          <code class="literal">
           00
          </code>
          ..
          <code class="literal">
           59
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %s
          </code>
         </td>
         <td>
          Seconds (
          <code class="literal">
           00
          </code>
          ..
          <code class="literal">
           59
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %T
          </code>
         </td>
         <td>
          Time, 24-hour (
          <em class="replaceable">
           <code>
            hh:mm:ss
           </code>
          </em>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %U
          </code>
         </td>
         <td>
          Week (
          <code class="literal">
           00
          </code>
          ..
          <code class="literal">
           53
          </code>
          ), where Sunday is the
                first day of the week;
          <a class="link" href="date-and-time-functions.html#function_week">
           <code class="literal">
            WEEK()
           </code>
          </a>
          mode 0
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %u
          </code>
         </td>
         <td>
          Week (
          <code class="literal">
           00
          </code>
          ..
          <code class="literal">
           53
          </code>
          ), where Monday is the
                first day of the week;
          <a class="link" href="date-and-time-functions.html#function_week">
           <code class="literal">
            WEEK()
           </code>
          </a>
          mode 1
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %V
          </code>
         </td>
         <td>
          Week (
          <code class="literal">
           01
          </code>
          ..
          <code class="literal">
           53
          </code>
          ), where Sunday is the
                first day of the week;
          <a class="link" href="date-and-time-functions.html#function_week">
           <code class="literal">
            WEEK()
           </code>
          </a>
          mode 2; used with
          <code class="literal">
           %X
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %v
          </code>
         </td>
         <td>
          Week (
          <code class="literal">
           01
          </code>
          ..
          <code class="literal">
           53
          </code>
          ), where Monday is the
                first day of the week;
          <a class="link" href="date-and-time-functions.html#function_week">
           <code class="literal">
            WEEK()
           </code>
          </a>
          mode 3; used with
          <code class="literal">
           %x
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %W
          </code>
         </td>
         <td>
          Weekday name (
          <code class="literal">
           Sunday
          </code>
          ..
          <code class="literal">
           Saturday
          </code>
          )
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %w
          </code>
         </td>
         <td>
          Day of the week
                (
          <code class="literal">
           0
          </code>
          =Sunday..
          <code class="literal">
           6
          </code>
          =Saturday)
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %X
          </code>
         </td>
         <td>
          Year for the week where Sunday is the first day of the week, numeric,
                four digits; used with
          <code class="literal">
           %V
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %x
          </code>
         </td>
         <td>
          Year for the week, where Monday is the first day of the week, numeric,
                four digits; used with
          <code class="literal">
           %v
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %Y
          </code>
         </td>
         <td>
          Year, numeric, four digits
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %y
          </code>
         </td>
         <td>
          Year, numeric (two digits)
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %%
          </code>
         </td>
         <td>
          A literal
          <code class="literal">
           %
          </code>
          character
         </td>
        </tr>
        <tr>
         <td>
          <code class="literal">
           %
           <em class="replaceable">
            <code>
             x
            </code>
           </em>
          </code>
         </td>
         <td>
          <em class="replaceable">
           <code>
            x
           </code>
          </em>
          , for any
          <span class="quote">
           “
           <span class="quote">
            <em class="replaceable">
             <code>
              x
             </code>
            </em>
           </span>
           ”
          </span>
          not listed
                above
         </td>
        </tr>
       </tbody>
      </table>
     </div>
     <div class="informaltable">
      <table cellpadding="0" cellspacing="0" style="position: fixed; top: 0px; display: none; left: 431px; width: 709px;">
       <thead>
        <tr>
         <th style="width: 157.328px;">
          Specifier
         </th>
         <th style="width: 550.672px;">
          Description
         </th>
        </tr>
       </thead>
      </table>
     </div>
     <p>
      Ranges for the month and day specifiers begin with zero due to
          the fact that MySQL permits the storing of incomplete dates
          such as
      <code class="literal">
       '2014-00-00'
      </code>
      .
     </p>
     <p>
      The language used for day and month names and abbreviations is
          controlled by the value of the
      <a class="link" href="server-system-variables.html#sysvar_lc_time_names">
       <code class="literal">
        lc_time_names
       </code>
      </a>
      system variable
          (
      <a class="xref" href="locale-support.html" title="12.16 MySQL Server Locale Support">
       Section 12.16, “MySQL Server Locale Support”
      </a>
      ).
     </p>
     <p>
      For the
      <code class="literal">
       %U
      </code>
      ,
      <code class="literal">
       %u
      </code>
      ,
      <code class="literal">
       %V
      </code>
      , and
      <code class="literal">
       %v
      </code>
      specifiers,
          see the description of the
      <a class="link" href="date-and-time-functions.html#function_week">
       <code class="literal">
        WEEK()
       </code>
      </a>
      function for information
          about the mode values. The mode affects how week numbering
          occurs.
     </p>
     <p>
      <a class="link" href="date-and-time-functions.html#function_date-format">
       <code class="literal">
        DATE_FORMAT()
       </code>
      </a>
      returns a string
          with a character set and collation given by
      <a class="link" href="server-system-variables.html#sysvar_character_set_connection">
       <code class="literal">
        character_set_connection
       </code>
      </a>
      and
      <a class="link" href="server-system-variables.html#sysvar_collation_connection">
       <code class="literal">
        collation_connection
       </code>
      </a>
      so that
          it can return month and weekday names containing non-ASCII
          characters.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa69421949"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_FORMAT</span><span class="token punctuation">(</span><span class="token string">'2009-10-04 22:23:00'</span><span class="token punctuation">,</span> <span class="token string">'%W %M %Y'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'Sunday October 2009'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_FORMAT</span><span class="token punctuation">(</span><span class="token string">'2007-10-04 22:23:00'</span><span class="token punctuation">,</span> <span class="token string">'%H:%i:%s'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'22:23:00'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_FORMAT</span><span class="token punctuation">(</span><span class="token string">'1900-10-04 22:23:00'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>                 <span class="token string">'%D %y %a %d %m %b %j'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'4th 00 Thu 04 10 Oct 277'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_FORMAT</span><span class="token punctuation">(</span><span class="token string">'1997-10-04 22:23:00'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>                 <span class="token string">'%H %k %I %r %T %S %w'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'22 22 10 10:23:00 PM 22:23:00 00 6'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_FORMAT</span><span class="token punctuation">(</span><span class="token string">'1999-01-01'</span><span class="token punctuation">,</span> <span class="token string">'%X %V'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'1998 52'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_FORMAT</span><span class="token punctuation">(</span><span class="token string">'2006-06-00'</span><span class="token punctuation">,</span> <span class="token string">'%d'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'00'</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_date-sub">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_date-sub">
       <code class="literal">
        DATE_SUB(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        ,INTERVAL
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        <em class="replaceable">
         <code>
          unit
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204953808">
     </a>
     <p>
      See the description for
      <a class="link" href="date-and-time-functions.html#function_date-add">
       <code class="literal">
        DATE_ADD()
       </code>
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_day">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_day">
       <code class="literal">
        DAY(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204944736">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_day">
       <code class="literal">
        DAY()
       </code>
      </a>
      is a synonym for
      <a class="link" href="date-and-time-functions.html#function_dayofmonth">
       <code class="literal">
        DAYOFMONTH()
       </code>
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_dayname">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_dayname">
       <code class="literal">
        DAYNAME(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204934368">
     </a>
     <p>
      Returns the name of the weekday for
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      . The language used for the
          name is controlled by the value of the
      <a class="link" href="server-system-variables.html#sysvar_lc_time_names">
       <code class="literal">
        lc_time_names
       </code>
      </a>
      system variable
          (see
      <a class="xref" href="locale-support.html" title="12.16 MySQL Server Locale Support">
       Section 12.16, “MySQL Server Locale Support”
      </a>
      ). Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa88421390"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DAYNAME</span><span class="token punctuation">(</span><span class="token string">'2007-02-03'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'Saturday'</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_dayofmonth">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_dayofmonth">
       <code class="literal">
        DAYOFMONTH(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204919888">
     </a>
     <p>
      Returns the day of the month for
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      , in the range
      <code class="literal">
       1
      </code>
      to
      <code class="literal">
       31
      </code>
      , or
      <code class="literal">
       0
      </code>
      for dates such as
      <code class="literal">
       '0000-00-00'
      </code>
      or
      <code class="literal">
       '2008-00-00'
      </code>
      that have a zero day part.
          Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa12279360"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DAYOFMONTH</span><span class="token punctuation">(</span><span class="token string">'2007-02-03'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">3</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_dayofweek">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_dayofweek">
       <code class="literal">
        DAYOFWEEK(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204903840">
     </a>
     <p>
      Returns the weekday index for
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      (
      <code class="literal">
       1
      </code>
      = Sunday,
      <code class="literal">
       2
      </code>
      = Monday,
          …,
      <code class="literal">
       7
      </code>
      = Saturday). These index values
          correspond to the ODBC standard. Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa31891283"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DAYOFWEEK</span><span class="token punctuation">(</span><span class="token string">'2007-02-03'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">7</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_dayofyear">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_dayofyear">
       <code class="literal">
        DAYOFYEAR(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204889184">
     </a>
     <p>
      Returns the day of the year for
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      , in the range
      <code class="literal">
       1
      </code>
      to
      <code class="literal">
       366
      </code>
      . Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa39143255"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DAYOFYEAR</span><span class="token punctuation">(</span><span class="token string">'2007-02-03'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">34</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_extract">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_extract">
       <code class="literal">
        EXTRACT(
        <em class="replaceable">
         <code>
          unit
         </code>
        </em>
        FROM
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204874864">
     </a>
     <p>
      The
      <a class="link" href="date-and-time-functions.html#function_extract">
       <code class="literal">
        EXTRACT()
       </code>
      </a>
      function uses the
          same kinds of
      <em class="replaceable">
       <code>
        unit
       </code>
      </em>
      specifiers as
      <a class="link" href="date-and-time-functions.html#function_date-add">
       <code class="literal">
        DATE_ADD()
       </code>
      </a>
      or
      <a class="link" href="date-and-time-functions.html#function_date-sub">
       <code class="literal">
        DATE_SUB()
       </code>
      </a>
      , but extracts parts
          from the date rather than performing date arithmetic. For
          information on the
      <em class="replaceable">
       <code>
        unit
       </code>
      </em>
      argument,
          see
      <a class="xref" href="expressions.html#temporal-intervals" title="Temporal Intervals">
       Temporal Intervals
      </a>
      . Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa69377489"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">EXTRACT</span><span class="token punctuation">(</span><span class="token datatype">YEAR</span> <span class="token keyword">FROM</span> <span class="token string">'2019-07-02'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">2019</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">EXTRACT</span><span class="token punctuation">(</span><span class="token keyword">YEAR_MONTH</span> <span class="token keyword">FROM</span> <span class="token string">'2019-07-02 01:02:03'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">201907</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">EXTRACT</span><span class="token punctuation">(</span><span class="token keyword">DAY_MINUTE</span> <span class="token keyword">FROM</span> <span class="token string">'2019-07-02 01:02:03'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">20102</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">EXTRACT</span><span class="token punctuation">(</span><span class="token keyword">MICROSECOND</span>
<span class="token prompt">    -&gt;</span>                <span class="token keyword">FROM</span> <span class="token string">'2003-01-02 10:30:00.000123'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">123</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_from-days">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_from-days">
       <code class="literal">
        FROM_DAYS(
        <em class="replaceable">
         <code>
          N
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204854320">
     </a>
     <p>
      Given a day number
      <em class="replaceable">
       <code>
        N
       </code>
      </em>
      , returns a
      <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
       <code class="literal">
        DATE
       </code>
      </a>
      value. Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        N
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa39363977"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">FROM_DAYS</span><span class="token punctuation">(</span><span class="token number">730669</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2000-07-03'</span></code></pre>
     </div>
     <p>
      Use
      <a class="link" href="date-and-time-functions.html#function_from-days">
       <code class="literal">
        FROM_DAYS()
       </code>
      </a>
      with caution on
          old dates. It is not intended for use with values that precede
          the advent of the Gregorian calendar (1582). See
      <a class="xref" href="mysql-calendar.html" title="13.2.7 What Calendar Is Used By MySQL?">
       Section 13.2.7, “What Calendar Is Used By MySQL?”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_from-unixtime">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_from-unixtime">
       <code class="literal">
        FROM_UNIXTIME(
        <em class="replaceable">
         <code>
          unix_timestamp
         </code>
        </em>
        [,
        <em class="replaceable">
         <code>
          format
         </code>
        </em>
        ])
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204837600">
     </a>
     <p>
      Returns a representation of
      <em class="replaceable">
       <code>
        unix_timestamp
       </code>
      </em>
      as a datetime or
          character string value. The value returned is expressed using
          the session time zone. (Clients can set the session time zone
          as described in
      <a class="xref" href="time-zone-support.html" title="7.1.15 MySQL Server Time Zone Support">
       Section 7.1.15, “MySQL Server Time Zone Support”
      </a>
      .)
      <em class="replaceable">
       <code>
        unix_timestamp
       </code>
      </em>
      is an internal
          timestamp value representing seconds since
      <code class="literal">
       '1970-01-01 00:00:00'
      </code>
      UTC, such as produced
          by the
      <a class="link" href="date-and-time-functions.html#function_unix-timestamp">
       <code class="literal">
        UNIX_TIMESTAMP()
       </code>
      </a>
      function.
     </p>
     <p>
      If
      <em class="replaceable">
       <code>
        format
       </code>
      </em>
      is omitted, this function
          returns a
      <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
       <code class="literal">
        DATETIME
       </code>
      </a>
      value.
     </p>
     <p>
      If
      <em class="replaceable">
       <code>
        unix_timestamp
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        format
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      ,
          this function returns
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      If
      <em class="replaceable">
       <code>
        unix_timestamp
       </code>
      </em>
      is an integer,
          the fractional seconds precision of the
      <code class="literal">
       DATETIME
      </code>
      is zero. When
      <em class="replaceable">
       <code>
        unix_timestamp
       </code>
      </em>
      is a decimal value,
          the fractional seconds precision of the
      <code class="literal">
       DATETIME
      </code>
      is the same as the precision of
          the decimal value, up to a maximum of 6. When
      <em class="replaceable">
       <code>
        unix_timestamp
       </code>
      </em>
      is a floating point
          number, the fractional seconds precision of the datetime is 6.
     </p>
     <p>
      On 32-bit platforms, the maximum useful value for
      <em class="replaceable">
       <code>
        unix_timestamp
       </code>
      </em>
      is
          2147483647.999999, which returns
      <code class="literal">
       '2038-01-19
          03:14:07.999999'
      </code>
      UTC. On 64-bit platforms, the
          effective maximum is 32536771199.999999, which returns
      <code class="literal">
       '3001-01-18 23:59:59.999999'
      </code>
      UTC.
          Regardless of platform or version, a greater value for
      <em class="replaceable">
       <code>
        unix_timestamp
       </code>
      </em>
      than the effective
          maximum returns
      <code class="literal">
       0
      </code>
      .
     </p>
     <p>
      <em class="replaceable">
       <code>
        format
       </code>
      </em>
      is used to format the result
          in the same way as the format string used for the
      <a class="link" href="date-and-time-functions.html#function_date-format">
       <code class="literal">
        DATE_FORMAT()
       </code>
      </a>
      function. If
      <em class="replaceable">
       <code>
        format
       </code>
      </em>
      is supplied, the value
          returned is a
      <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
       <code class="literal">
        VARCHAR
       </code>
      </a>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa9323320"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">FROM_UNIXTIME</span><span class="token punctuation">(</span><span class="token number">1447430881</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2015-11-13 10:08:01'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">FROM_UNIXTIME</span><span class="token punctuation">(</span><span class="token number">1447430881</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">20151113100801</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">FROM_UNIXTIME</span><span class="token punctuation">(</span><span class="token number">1447430881</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>                      <span class="token string">'%Y %D %M %h:%i:%s %x'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2015 13th November 10:08:01 2015'</span></code></pre>
     </div>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       If you use
       <a class="link" href="date-and-time-functions.html#function_unix-timestamp">
        <code class="literal">
         UNIX_TIMESTAMP()
        </code>
       </a>
       and
       <a class="link" href="date-and-time-functions.html#function_from-unixtime">
        <code class="literal">
         FROM_UNIXTIME()
        </code>
       </a>
       to
            convert between values in a non-UTC time zone and Unix
            timestamp values, the conversion is lossy because the
            mapping is not one-to-one in both directions. For details,
            see the description of the
       <a class="link" href="date-and-time-functions.html#function_unix-timestamp">
        <code class="literal">
         UNIX_TIMESTAMP()
        </code>
       </a>
       function.
      </p>
     </div>
    </li>
    <li class="listitem">
     <a name="function_get-format">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_get-format">
       <code class="literal">
        GET_FORMAT({DATE|TIME|DATETIME},
          {'EUR'|'USA'|'JIS'|'ISO'|'INTERNAL'})
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204800704">
     </a>
     <p>
      Returns a format string. This function is useful in
          combination with the
      <a class="link" href="date-and-time-functions.html#function_date-format">
       <code class="literal">
        DATE_FORMAT()
       </code>
      </a>
      and the
      <a class="link" href="date-and-time-functions.html#function_str-to-date">
       <code class="literal">
        STR_TO_DATE()
       </code>
      </a>
      functions.
     </p>
     <p>
      If
      <em class="replaceable">
       <code>
        format
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      , this function returns
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      The possible values for the first and second arguments result
          in several possible format strings (for the specifiers used,
          see the table in the
      <a class="link" href="date-and-time-functions.html#function_date-format">
       <code class="literal">
        DATE_FORMAT()
       </code>
      </a>
      function
          description). ISO format refers to ISO 9075, not ISO 8601.
     </p>
     <div class="informaltable">
      <table summary="Function calls for the GET_FORMAT function along with results for each function call.">
       <colgroup>
        <col style="width: 60%"/>
        <col style="width: 40%"/>
       </colgroup>
       <thead>
        <tr>
         <th>
          Function Call
         </th>
         <th>
          Result
         </th>
        </tr>
       </thead>
       <tbody>
        <tr>
         <td>
          <a class="link" href="date-and-time-functions.html#function_get-format">
           <code class="literal">
            GET_FORMAT(DATE,'USA')
           </code>
          </a>
         </td>
         <td>
          <code class="literal">
           '%m.%d.%Y'
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <a class="link" href="date-and-time-functions.html#function_get-format">
           <code class="literal">
            GET_FORMAT(DATE,'JIS')
           </code>
          </a>
         </td>
         <td>
          <code class="literal">
           '%Y-%m-%d'
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <a class="link" href="date-and-time-functions.html#function_get-format">
           <code class="literal">
            GET_FORMAT(DATE,'ISO')
           </code>
          </a>
         </td>
         <td>
          <code class="literal">
           '%Y-%m-%d'
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <a class="link" href="date-and-time-functions.html#function_get-format">
           <code class="literal">
            GET_FORMAT(DATE,'EUR')
           </code>
          </a>
         </td>
         <td>
          <code class="literal">
           '%d.%m.%Y'
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <a class="link" href="date-and-time-functions.html#function_get-format">
           <code class="literal">
            GET_FORMAT(DATE,'INTERNAL')
           </code>
          </a>
         </td>
         <td>
          <code class="literal">
           '%Y%m%d'
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <a class="link" href="date-and-time-functions.html#function_get-format">
           <code class="literal">
            GET_FORMAT(DATETIME,'USA')
           </code>
          </a>
         </td>
         <td>
          <code class="literal">
           '%Y-%m-%d %H.%i.%s'
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <a class="link" href="date-and-time-functions.html#function_get-format">
           <code class="literal">
            GET_FORMAT(DATETIME,'JIS')
           </code>
          </a>
         </td>
         <td>
          <code class="literal">
           '%Y-%m-%d %H:%i:%s'
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <a class="link" href="date-and-time-functions.html#function_get-format">
           <code class="literal">
            GET_FORMAT(DATETIME,'ISO')
           </code>
          </a>
         </td>
         <td>
          <code class="literal">
           '%Y-%m-%d %H:%i:%s'
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <a class="link" href="date-and-time-functions.html#function_get-format">
           <code class="literal">
            GET_FORMAT(DATETIME,'EUR')
           </code>
          </a>
         </td>
         <td>
          <code class="literal">
           '%Y-%m-%d %H.%i.%s'
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <a class="link" href="date-and-time-functions.html#function_get-format">
           <code class="literal">
            GET_FORMAT(DATETIME,'INTERNAL')
           </code>
          </a>
         </td>
         <td>
          <code class="literal">
           '%Y%m%d%H%i%s'
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <a class="link" href="date-and-time-functions.html#function_get-format">
           <code class="literal">
            GET_FORMAT(TIME,'USA')
           </code>
          </a>
         </td>
         <td>
          <code class="literal">
           '%h:%i:%s %p'
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <a class="link" href="date-and-time-functions.html#function_get-format">
           <code class="literal">
            GET_FORMAT(TIME,'JIS')
           </code>
          </a>
         </td>
         <td>
          <code class="literal">
           '%H:%i:%s'
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <a class="link" href="date-and-time-functions.html#function_get-format">
           <code class="literal">
            GET_FORMAT(TIME,'ISO')
           </code>
          </a>
         </td>
         <td>
          <code class="literal">
           '%H:%i:%s'
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <a class="link" href="date-and-time-functions.html#function_get-format">
           <code class="literal">
            GET_FORMAT(TIME,'EUR')
           </code>
          </a>
         </td>
         <td>
          <code class="literal">
           '%H.%i.%s'
          </code>
         </td>
        </tr>
        <tr>
         <td>
          <a class="link" href="date-and-time-functions.html#function_get-format">
           <code class="literal">
            GET_FORMAT(TIME,'INTERNAL')
           </code>
          </a>
         </td>
         <td>
          <code class="literal">
           '%H%i%s'
          </code>
         </td>
        </tr>
       </tbody>
      </table>
     </div>
     <div class="informaltable">
      <table cellpadding="0" cellspacing="0" style="position: fixed; top: 0px; display: none; left: 431px; width: 432px;">
       <thead>
        <tr>
         <th style="width: 258.891px;">
          Function Call
         </th>
         <th style="width: 172.594px;">
          Result
         </th>
        </tr>
       </thead>
      </table>
     </div>
     <p>
      <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
       <code class="literal">
        TIMESTAMP
       </code>
      </a>
      can also be used as
          the first argument to
      <a class="link" href="date-and-time-functions.html#function_get-format">
       <code class="literal">
        GET_FORMAT()
       </code>
      </a>
      , in which case the
          function returns the same values as for
      <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
       <code class="literal">
        DATETIME
       </code>
      </a>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa36989675"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_FORMAT</span><span class="token punctuation">(</span><span class="token string">'2003-10-03'</span><span class="token punctuation">,</span><span class="token function">GET_FORMAT</span><span class="token punctuation">(</span><span class="token datatype">DATE</span><span class="token punctuation">,</span><span class="token string">'EUR'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'03.10.2003'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STR_TO_DATE</span><span class="token punctuation">(</span><span class="token string">'10.31.2003'</span><span class="token punctuation">,</span><span class="token function">GET_FORMAT</span><span class="token punctuation">(</span><span class="token datatype">DATE</span><span class="token punctuation">,</span><span class="token string">'USA'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2003-10-31'</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_hour">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_hour">
       <code class="literal">
        HOUR(
        <em class="replaceable">
         <code>
          time
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204720416">
     </a>
     <p>
      Returns the hour for
      <em class="replaceable">
       <code>
        time
       </code>
      </em>
      . The
          range of the return value is
      <code class="literal">
       0
      </code>
      to
      <code class="literal">
       23
      </code>
      for time-of-day values. However, the
          range of
      <a class="link" href="time.html" title="13.2.3 The TIME Type">
       <code class="literal">
        TIME
       </code>
      </a>
      values actually
          is much larger, so
      <code class="literal">
       HOUR
      </code>
      can return values
          greater than
      <code class="literal">
       23
      </code>
      . Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        time
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa79792162"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">HOUR</span><span class="token punctuation">(</span><span class="token string">'10:05:03'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">10</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">HOUR</span><span class="token punctuation">(</span><span class="token string">'272:59:59'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">272</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_last-day">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_last-day">
       <code class="literal">
        LAST_DAY(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204703056">
     </a>
     <p>
      Takes a date or datetime value and returns the corresponding
          value for the last day of the month. Returns
      <code class="literal">
       NULL
      </code>
      if the argument is invalid or
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa83855621"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">LAST_DAY</span><span class="token punctuation">(</span><span class="token string">'2003-02-05'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2003-02-28'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">LAST_DAY</span><span class="token punctuation">(</span><span class="token string">'2004-02-05'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2004-02-29'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">LAST_DAY</span><span class="token punctuation">(</span><span class="token string">'2004-01-01 01:01:01'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2004-01-31'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">LAST_DAY</span><span class="token punctuation">(</span><span class="token string">'2003-03-32'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token boolean">NULL</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_localtime">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_localtime">
       <code class="literal">
        LOCALTIME
       </code>
      </a>
      ,
      <a class="link" href="date-and-time-functions.html#function_localtime">
       <code class="literal">
        LOCALTIME([
        <em class="replaceable">
         <code>
          fsp
         </code>
        </em>
        ])
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204687744">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_localtime">
       <code class="literal">
        LOCALTIME
       </code>
      </a>
      and
      <a class="link" href="date-and-time-functions.html#function_localtime">
       <code class="literal">
        LOCALTIME()
       </code>
      </a>
      are synonyms for
      <a class="link" href="date-and-time-functions.html#function_now">
       <code class="literal">
        NOW()
       </code>
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_localtimestamp">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_localtimestamp">
       <code class="literal">
        LOCALTIMESTAMP
       </code>
      </a>
      ,
      <a class="link" href="date-and-time-functions.html#function_localtimestamp">
       <code class="literal">
        LOCALTIMESTAMP([
        <em class="replaceable">
         <code>
          fsp
         </code>
        </em>
        ])
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204674944">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_localtimestamp">
       <code class="literal">
        LOCALTIMESTAMP
       </code>
      </a>
      and
      <a class="link" href="date-and-time-functions.html#function_localtimestamp">
       <code class="literal">
        LOCALTIMESTAMP()
       </code>
      </a>
      are synonyms
          for
      <a class="link" href="date-and-time-functions.html#function_now">
       <code class="literal">
        NOW()
       </code>
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_makedate">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_makedate">
       <code class="literal">
        MAKEDATE(
        <em class="replaceable">
         <code>
          year
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          dayofyear
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204662928">
     </a>
     <p>
      Returns a date, given year and day-of-year values.
      <em class="replaceable">
       <code>
        dayofyear
       </code>
      </em>
      must be greater than 0 or
          the result is
      <code class="literal">
       NULL
      </code>
      . The result is also
      <code class="literal">
       NULL
      </code>
      if either argument is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa65075204"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">MAKEDATE</span><span class="token punctuation">(</span><span class="token number">2011</span><span class="token punctuation">,</span><span class="token number">31</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">MAKEDATE</span><span class="token punctuation">(</span><span class="token number">2011</span><span class="token punctuation">,</span><span class="token number">32</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2011-01-31'</span><span class="token punctuation">,</span> <span class="token string">'2011-02-01'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">MAKEDATE</span><span class="token punctuation">(</span><span class="token number">2011</span><span class="token punctuation">,</span><span class="token number">365</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">MAKEDATE</span><span class="token punctuation">(</span><span class="token number">2014</span><span class="token punctuation">,</span><span class="token number">365</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2011-12-31'</span><span class="token punctuation">,</span> <span class="token string">'2014-12-31'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">MAKEDATE</span><span class="token punctuation">(</span><span class="token number">2011</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token boolean">NULL</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_maketime">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_maketime">
       <code class="literal">
        MAKETIME(
        <em class="replaceable">
         <code>
          hour
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          minute
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          second
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204647552">
     </a>
     <p>
      Returns a time value calculated from the
      <em class="replaceable">
       <code>
        hour
       </code>
      </em>
      ,
      <em class="replaceable">
       <code>
        minute
       </code>
      </em>
      , and
      <em class="replaceable">
       <code>
        second
       </code>
      </em>
      arguments. Returns
      <code class="literal">
       NULL
      </code>
      if any of its arguments are
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      The
      <em class="replaceable">
       <code>
        second
       </code>
      </em>
      argument can have a
          fractional part.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa90957137"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">MAKETIME</span><span class="token punctuation">(</span><span class="token number">12</span><span class="token punctuation">,</span><span class="token number">15</span><span class="token punctuation">,</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'12:15:30'</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_microsecond">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_microsecond">
       <code class="literal">
        MICROSECOND(
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204633664">
     </a>
     <p>
      Returns the microseconds from the time or datetime expression
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      as a number in the range from
      <code class="literal">
       0
      </code>
      to
      <code class="literal">
       999999
      </code>
      . Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa37178863"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">MICROSECOND</span><span class="token punctuation">(</span><span class="token string">'12:00:00.123456'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">123456</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">MICROSECOND</span><span class="token punctuation">(</span><span class="token string">'2019-12-31 23:59:59.000010'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">10</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_minute">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_minute">
       <code class="literal">
        MINUTE(
        <em class="replaceable">
         <code>
          time
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204618896">
     </a>
     <p>
      Returns the minute for
      <em class="replaceable">
       <code>
        time
       </code>
      </em>
      , in the
          range
      <code class="literal">
       0
      </code>
      to
      <code class="literal">
       59
      </code>
      , or
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        time
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa45938871"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">MINUTE</span><span class="token punctuation">(</span><span class="token string">'2008-02-03 10:05:03'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">5</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_month">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_month">
       <code class="literal">
        MONTH(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204605040">
     </a>
     <p>
      Returns the month for
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      , in the
          range
      <code class="literal">
       1
      </code>
      to
      <code class="literal">
       12
      </code>
      for
          January to December, or
      <code class="literal">
       0
      </code>
      for dates such as
      <code class="literal">
       '0000-00-00'
      </code>
      or
      <code class="literal">
       '2008-00-00'
      </code>
      that have a zero month part.
          Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa70880862"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">MONTH</span><span class="token punctuation">(</span><span class="token string">'2008-02-03'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">2</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_monthname">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_monthname">
       <code class="literal">
        MONTHNAME(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204588992">
     </a>
     <p>
      Returns the full name of the month for
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      . The language used for the
          name is controlled by the value of the
      <a class="link" href="server-system-variables.html#sysvar_lc_time_names">
       <code class="literal">
        lc_time_names
       </code>
      </a>
      system variable
          (
      <a class="xref" href="locale-support.html" title="12.16 MySQL Server Locale Support">
       Section 12.16, “MySQL Server Locale Support”
      </a>
      ). Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa46704182"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">MONTHNAME</span><span class="token punctuation">(</span><span class="token string">'2008-02-03'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'February'</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_now">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_now">
       <code class="literal">
        NOW([
        <em class="replaceable">
         <code>
          fsp
         </code>
        </em>
        ])
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204574592">
     </a>
     <p>
      Returns the current date and time as a value in
      <code class="literal">
       '
       <em class="replaceable">
        <code>
         YYYY-MM-DD
          hh:mm:ss
        </code>
       </em>
       '
      </code>
      or
      <em class="replaceable">
       <code>
        YYYYMMDDhhmmss
       </code>
      </em>
      format, depending on
          whether the function is used in string or numeric context. The
          value is expressed in the session time zone.
     </p>
     <p>
      If the
      <em class="replaceable">
       <code>
        fsp
       </code>
      </em>
      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.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa44409057"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">NOW</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2007-12-15 23:50:26'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">NOW</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">20071215235026.000000</span></code></pre>
     </div>
     <p>
      <a class="link" href="date-and-time-functions.html#function_now">
       <code class="literal">
        NOW()
       </code>
      </a>
      returns a constant time
          that indicates the time at which the statement began to
          execute. (Within a stored function or trigger,
      <a class="link" href="date-and-time-functions.html#function_now">
       <code class="literal">
        NOW()
       </code>
      </a>
      returns the time at which
          the function or triggering statement began to execute.) This
          differs from the behavior for
      <a class="link" href="date-and-time-functions.html#function_sysdate">
       <code class="literal">
        SYSDATE()
       </code>
      </a>
      , which returns the
          exact time at which it executes.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa62500855"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">NOW</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">SLEEP</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">NOW</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> NOW()               <span class="token punctuation">|</span> SLEEP(2) <span class="token punctuation">|</span> NOW()               <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 2006<span class="token punctuation">-</span>04<span class="token punctuation">-</span>12 13:47:36 <span class="token punctuation">|</span>        0 <span class="token punctuation">|</span> 2006<span class="token punctuation">-</span>04<span class="token punctuation">-</span>12 13:47:36 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">SYSDATE</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">SLEEP</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">SYSDATE</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> SYSDATE()           <span class="token punctuation">|</span> SLEEP(2) <span class="token punctuation">|</span> SYSDATE()           <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 2006<span class="token punctuation">-</span>04<span class="token punctuation">-</span>12 13:47:44 <span class="token punctuation">|</span>        0 <span class="token punctuation">|</span> 2006<span class="token punctuation">-</span>04<span class="token punctuation">-</span>12 13:47:46 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
     </div>
     <p>
      In addition, the
      <code class="literal">
       SET TIMESTAMP
      </code>
      statement
          affects the value returned by
      <a class="link" href="date-and-time-functions.html#function_now">
       <code class="literal">
        NOW()
       </code>
      </a>
      but not by
      <a class="link" href="date-and-time-functions.html#function_sysdate">
       <code class="literal">
        SYSDATE()
       </code>
      </a>
      . This means that
          timestamp settings in the binary log have no effect on
          invocations of
      <a class="link" href="date-and-time-functions.html#function_sysdate">
       <code class="literal">
        SYSDATE()
       </code>
      </a>
      .
          Setting the timestamp to a nonzero value causes each
          subsequent invocation of
      <a class="link" href="date-and-time-functions.html#function_now">
       <code class="literal">
        NOW()
       </code>
      </a>
      to return that value. Setting the timestamp to zero cancels
          this effect so that
      <a class="link" href="date-and-time-functions.html#function_now">
       <code class="literal">
        NOW()
       </code>
      </a>
      once
          again returns the current date and time.
     </p>
     <p>
      See the description for
      <a class="link" href="date-and-time-functions.html#function_sysdate">
       <code class="literal">
        SYSDATE()
       </code>
      </a>
      for additional
          information about the differences between the two functions.
     </p>
    </li>
    <li class="listitem">
     <a name="function_period-add">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_period-add">
       <code class="literal">
        PERIOD_ADD(
        <em class="replaceable">
         <code>
          P
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          N
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204543440">
     </a>
     <p>
      Adds
      <em class="replaceable">
       <code>
        N
       </code>
      </em>
      months to period
      <em class="replaceable">
       <code>
        P
       </code>
      </em>
      (in the format
      <em class="replaceable">
       <code>
        YYMM
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        YYYYMM
       </code>
      </em>
      ). Returns a value in the
          format
      <em class="replaceable">
       <code>
        YYYYMM
       </code>
      </em>
      .
     </p>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       The period argument
       <em class="replaceable">
        <code>
         P
        </code>
       </em>
       is
       <span class="emphasis">
        <em>
         not
        </em>
       </span>
       a date value.
      </p>
     </div>
     <p>
      This function returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        P
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        N
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa92951194"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">PERIOD_ADD</span><span class="token punctuation">(</span><span class="token number">200801</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">200803</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_period-diff">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_period-diff">
       <code class="literal">
        PERIOD_DIFF(
        <em class="replaceable">
         <code>
          P1
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          P2
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204526320">
     </a>
     <p>
      Returns the number of months between periods
      <em class="replaceable">
       <code>
        P1
       </code>
      </em>
      and
      <em class="replaceable">
       <code>
        P2
       </code>
      </em>
      .
      <em class="replaceable">
       <code>
        P1
       </code>
      </em>
      and
      <em class="replaceable">
       <code>
        P2
       </code>
      </em>
      should be in the format
      <em class="replaceable">
       <code>
        YYMM
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        YYYYMM
       </code>
      </em>
      . Note that the period
          arguments
      <em class="replaceable">
       <code>
        P1
       </code>
      </em>
      and
      <em class="replaceable">
       <code>
        P2
       </code>
      </em>
      are
      <span class="emphasis">
       <em>
        not
       </em>
      </span>
      date values.
     </p>
     <p>
      This function returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        P1
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        P2
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa61866747"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">PERIOD_DIFF</span><span class="token punctuation">(</span><span class="token number">200802</span><span class="token punctuation">,</span><span class="token number">200703</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">11</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_quarter">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_quarter">
       <code class="literal">
        QUARTER(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204509680">
     </a>
     <p>
      Returns the quarter of the year for
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      , in the range
      <code class="literal">
       1
      </code>
      to
      <code class="literal">
       4
      </code>
      , or
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa51633752"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">QUARTER</span><span class="token punctuation">(</span><span class="token string">'2008-04-01'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">2</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_second">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_second">
       <code class="literal">
        SECOND(
        <em class="replaceable">
         <code>
          time
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204495792">
     </a>
     <p>
      Returns the second for
      <em class="replaceable">
       <code>
        time
       </code>
      </em>
      , in the
          range
      <code class="literal">
       0
      </code>
      to
      <code class="literal">
       59
      </code>
      , or
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        time
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa66612467"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">SECOND</span><span class="token punctuation">(</span><span class="token string">'10:05:03'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">3</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_sec-to-time">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_sec-to-time">
       <code class="literal">
        SEC_TO_TIME(
        <em class="replaceable">
         <code>
          seconds
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204481936">
     </a>
     <p>
      Returns the
      <em class="replaceable">
       <code>
        seconds
       </code>
      </em>
      argument,
          converted to hours, minutes, and seconds, as a
      <a class="link" href="time.html" title="13.2.3 The TIME Type">
       <code class="literal">
        TIME
       </code>
      </a>
      value. The range of the
          result is constrained to that of the
      <a class="link" href="time.html" title="13.2.3 The TIME Type">
       <code class="literal">
        TIME
       </code>
      </a>
      data type. A warning
          occurs if the argument corresponds to a value outside that
          range.
     </p>
     <p>
      The function returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        seconds
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa41130380"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">SEC_TO_TIME</span><span class="token punctuation">(</span><span class="token number">2378</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'00:39:38'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">SEC_TO_TIME</span><span class="token punctuation">(</span><span class="token number">2378</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">3938</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_str-to-date">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_str-to-date">
       <code class="literal">
        STR_TO_DATE(
        <em class="replaceable">
         <code>
          str
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          format
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204465248">
     </a>
     <p>
      This is the inverse of the
      <a class="link" href="date-and-time-functions.html#function_date-format">
       <code class="literal">
        DATE_FORMAT()
       </code>
      </a>
      function. It
          takes a string
      <em class="replaceable">
       <code>
        str
       </code>
      </em>
      and a format
          string
      <em class="replaceable">
       <code>
        format
       </code>
      </em>
      .
      <code class="literal">
       STR_TO_DATE()
      </code>
      returns a
      <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
       <code class="literal">
        DATETIME
       </code>
      </a>
      value if the format
          string contains both date and time parts, or a
      <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
       <code class="literal">
        DATE
       </code>
      </a>
      or
      <a class="link" href="time.html" title="13.2.3 The TIME Type">
       <code class="literal">
        TIME
       </code>
      </a>
      value if the string
          contains only date or time parts. If
      <em class="replaceable">
       <code>
        str
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        format
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      ,
          the function returns
      <code class="literal">
       NULL
      </code>
      . If the date,
          time, or datetime value extracted from
      <em class="replaceable">
       <code>
        str
       </code>
      </em>
      cannot be parsed according to
          the rules followed by the server,
      <code class="literal">
       STR_TO_DATE()
      </code>
      returns
      <code class="literal">
       NULL
      </code>
      and produces a warning.
     </p>
     <p>
      The server scans
      <em class="replaceable">
       <code>
        str
       </code>
      </em>
      attempting to
          match
      <em class="replaceable">
       <code>
        format
       </code>
      </em>
      to it. The format
          string can contain literal characters and format specifiers
          beginning with
      <code class="literal">
       %
      </code>
      . Literal characters in
      <em class="replaceable">
       <code>
        format
       </code>
      </em>
      must match literally in
      <em class="replaceable">
       <code>
        str
       </code>
      </em>
      . Format specifiers in
      <em class="replaceable">
       <code>
        format
       </code>
      </em>
      must match a date or time
          part in
      <em class="replaceable">
       <code>
        str
       </code>
      </em>
      . For the specifiers
          that can be used in
      <em class="replaceable">
       <code>
        format
       </code>
      </em>
      , see the
      <a class="link" href="date-and-time-functions.html#function_date-format">
       <code class="literal">
        DATE_FORMAT()
       </code>
      </a>
      function
          description.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa42898187"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STR_TO_DATE</span><span class="token punctuation">(</span><span class="token string">'01,5,2013'</span><span class="token punctuation">,</span><span class="token string">'%d,%m,%Y'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2013-05-01'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STR_TO_DATE</span><span class="token punctuation">(</span><span class="token string">'May 1, 2013'</span><span class="token punctuation">,</span><span class="token string">'%M %d,%Y'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2013-05-01'</span></code></pre>
     </div>
     <p>
      Scanning starts at the beginning of
      <em class="replaceable">
       <code>
        str
       </code>
      </em>
      and fails if
      <em class="replaceable">
       <code>
        format
       </code>
      </em>
      is found not to match. Extra
          characters at the end of
      <em class="replaceable">
       <code>
        str
       </code>
      </em>
      are
          ignored.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa45783478"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STR_TO_DATE</span><span class="token punctuation">(</span><span class="token string">'a09:30:17'</span><span class="token punctuation">,</span><span class="token string">'a%h:%i:%s'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'09:30:17'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STR_TO_DATE</span><span class="token punctuation">(</span><span class="token string">'a09:30:17'</span><span class="token punctuation">,</span><span class="token string">'%h:%i:%s'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token boolean">NULL</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STR_TO_DATE</span><span class="token punctuation">(</span><span class="token string">'09:30:17a'</span><span class="token punctuation">,</span><span class="token string">'%h:%i:%s'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'09:30:17'</span></code></pre>
     </div>
     <p>
      Unspecified date or time parts have a value of 0, so
          incompletely specified values in
      <em class="replaceable">
       <code>
        str
       </code>
      </em>
      produce a result with some or
          all parts set to 0:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa47575252"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STR_TO_DATE</span><span class="token punctuation">(</span><span class="token string">'abc'</span><span class="token punctuation">,</span><span class="token string">'abc'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'0000-00-00'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STR_TO_DATE</span><span class="token punctuation">(</span><span class="token string">'9'</span><span class="token punctuation">,</span><span class="token string">'%m'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'0000-09-00'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STR_TO_DATE</span><span class="token punctuation">(</span><span class="token string">'9'</span><span class="token punctuation">,</span><span class="token string">'%s'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'00:00:09'</span></code></pre>
     </div>
     <p>
      Range checking on the parts of date values is as described in
      <a class="xref" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
       Section 13.2.2, “The DATE, DATETIME, and TIMESTAMP Types”
      </a>
      . This means, for example, that
      <span class="quote">
       “
       <span class="quote">
        zero
       </span>
       ”
      </span>
      dates or dates with part values of 0 are
          permitted unless the SQL mode is set to disallow such values.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa68994674"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STR_TO_DATE</span><span class="token punctuation">(</span><span class="token string">'00/00/0000'</span><span class="token punctuation">,</span> <span class="token string">'%m/%d/%Y'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'0000-00-00'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STR_TO_DATE</span><span class="token punctuation">(</span><span class="token string">'04/31/2004'</span><span class="token punctuation">,</span> <span class="token string">'%m/%d/%Y'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2004-04-31'</span></code></pre>
     </div>
     <p>
      If the
      <a class="link" href="sql-mode.html#sqlmode_no_zero_date">
       <code class="literal">
        NO_ZERO_DATE
       </code>
      </a>
      SQL mode
          is enabled, zero dates are disallowed. In that case,
      <a class="link" href="date-and-time-functions.html#function_str-to-date">
       <code class="literal">
        STR_TO_DATE()
       </code>
      </a>
      returns
      <code class="literal">
       NULL
      </code>
      and generates a warning:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa68043559"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> sql_mode <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STR_TO_DATE</span><span class="token punctuation">(</span><span class="token string">'00/00/0000'</span><span class="token punctuation">,</span> <span class="token string">'%m/%d/%Y'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> STR_TO_DATE('00/00/0000', '%m/%d/%Y') <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 0000<span class="token punctuation">-</span>00<span class="token punctuation">-</span>00                            <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> sql_mode <span class="token operator">=</span> <span class="token string">'NO_ZERO_DATE'</span><span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STR_TO_DATE</span><span class="token punctuation">(</span><span class="token string">'00/00/0000'</span><span class="token punctuation">,</span> <span class="token string">'%m/%d/%Y'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> STR_TO_DATE('00/00/0000', '%m/%d/%Y') <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> NULL                                  <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">WARNINGS</span>\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
  Level<span class="token punctuation">:</span> Warning
   Code<span class="token punctuation">:</span> 1411
Message<span class="token punctuation">:</span> Incorrect datetime value<span class="token punctuation">:</span> '00/00/0000' for function str_to_date</span></code></pre>
     </div>
     <p>
      In some previous versions of MySQL, it was possible to pass an
          invalid date string such as
      <code class="literal">
       '2021-11-31'
      </code>
      to
          this function. In MySQL 8.4,
      <code class="literal">
       STR_TO_DATE()
      </code>
      performs complete range
          checking and raises an error if the date after conversion
          would be invalid.
     </p>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       You cannot use format
       <code class="literal">
        "%X%V"
       </code>
       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:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa84337674"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STR_TO_DATE</span><span class="token punctuation">(</span><span class="token string">'200442 Monday'</span><span class="token punctuation">,</span> <span class="token string">'%X%V %W'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2004-10-18'</span></code></pre>
      </div>
     </div>
     <p>
      You should also be aware that, for dates and the date portions
          of datetime values,
      <code class="literal">
       STR_TO_DATE()
      </code>
      checks
          (only) the individual year, month, and day of month values for
          validity. More precisely, this means that the year is checked
          to be sure that it is in the range 0-9999 inclusive, the month
          is checked to ensure that it is in the range 1-12 inclusive,
          and the day of month is checked to make sure that it is in the
          range 1-31 inclusive, but the server does not check the values
          in combination. For example,
      <code class="literal">
       SELECT
          STR_TO_DATE('23-2-31', '%Y-%m-%d')
      </code>
      returns
      <code class="literal">
       2023-02-31
      </code>
      . Enabling or disabling the
      <a class="link" href="sql-mode.html#sqlmode_allow_invalid_dates">
       <code class="literal">
        ALLOW_INVALID_DATES
       </code>
      </a>
      server
          SQL mode has no effect on this behavior. See
      <a class="xref" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
       Section 13.2.2, “The DATE, DATETIME, and TIMESTAMP Types”
      </a>
      , for more information.
     </p>
    </li>
    <li class="listitem">
     <a name="function_subdate">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_subdate">
       <code class="literal">
        SUBDATE(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        ,INTERVAL
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        <em class="replaceable">
         <code>
          unit
         </code>
        </em>
        )
       </code>
      </a>
      ,
      <a class="link" href="date-and-time-functions.html#function_subdate">
       <code class="literal">
        SUBDATE(
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          days
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204401376">
     </a>
     <p>
      When invoked with the
      <code class="literal">
       INTERVAL
      </code>
      form of the
          second argument,
      <a class="link" href="date-and-time-functions.html#function_subdate">
       <code class="literal">
        SUBDATE()
       </code>
      </a>
      is a
          synonym for
      <a class="link" href="date-and-time-functions.html#function_date-sub">
       <code class="literal">
        DATE_SUB()
       </code>
      </a>
      . For
          information on the
      <code class="literal">
       INTERVAL
      </code>
      <em class="replaceable">
       <code>
        unit
       </code>
      </em>
      argument, see the discussion
          for
      <a class="link" href="date-and-time-functions.html#function_date-add">
       <code class="literal">
        DATE_ADD()
       </code>
      </a>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa17055766"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_SUB</span><span class="token punctuation">(</span><span class="token string">'2008-01-02'</span><span class="token punctuation">,</span> <span class="token keyword">INTERVAL</span> <span class="token number">31</span> <span class="token keyword">DAY</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2007-12-02'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">SUBDATE</span><span class="token punctuation">(</span><span class="token string">'2008-01-02'</span><span class="token punctuation">,</span> <span class="token keyword">INTERVAL</span> <span class="token number">31</span> <span class="token keyword">DAY</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2007-12-02'</span></code></pre>
     </div>
     <p>
      The second form enables the use of an integer value for
      <em class="replaceable">
       <code>
        days
       </code>
      </em>
      . In such cases, it is
          interpreted as the number of days to be subtracted from the
          date or datetime expression
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa56991475"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">SUBDATE</span><span class="token punctuation">(</span><span class="token string">'2008-01-02 12:00:00'</span><span class="token punctuation">,</span> <span class="token number">31</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2007-12-02 12:00:00'</span></code></pre>
     </div>
     <p>
      This function returns
      <code class="literal">
       NULL
      </code>
      if any of its
          arguments are
      <code class="literal">
       NULL
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_subtime">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_subtime">
       <code class="literal">
        SUBTIME(
        <em class="replaceable">
         <code>
          expr1
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          expr2
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204379680">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_subtime">
       <code class="literal">
        SUBTIME()
       </code>
      </a>
      returns
      <em class="replaceable">
       <code>
        expr1
       </code>
      </em>
      −
      <em class="replaceable">
       <code>
        expr2
       </code>
      </em>
      expressed as a value in the
          same format as
      <em class="replaceable">
       <code>
        expr1
       </code>
      </em>
      .
      <em class="replaceable">
       <code>
        expr1
       </code>
      </em>
      is a time or datetime
          expression, and
      <em class="replaceable">
       <code>
        expr2
       </code>
      </em>
      is a time
          expression.
     </p>
     <p>
      Resolution of this function's return type is performed as
          it is for the
      <a class="link" href="date-and-time-functions.html#function_addtime">
       <code class="literal">
        ADDTIME()
       </code>
      </a>
      function; see the description of that function for more
          information.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa13194378"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">SUBTIME</span><span class="token punctuation">(</span><span class="token string">'2007-12-31 23:59:59.999999'</span><span class="token punctuation">,</span><span class="token string">'1 1:1:1.000002'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2007-12-30 22:58:58.999997'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">SUBTIME</span><span class="token punctuation">(</span><span class="token string">'01:00:00.999999'</span><span class="token punctuation">,</span> <span class="token string">'02:00:00.999998'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'-00:59:59.999999'</span></code></pre>
     </div>
     <p>
      This function returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        expr1
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        expr2
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_sysdate">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_sysdate">
       <code class="literal">
        SYSDATE([
        <em class="replaceable">
         <code>
          fsp
         </code>
        </em>
        ])
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204360528">
     </a>
     <p>
      Returns the current date and time as a value in
      <code class="literal">
       '
       <em class="replaceable">
        <code>
         YYYY-MM-DD
          hh:mm:ss
        </code>
       </em>
       '
      </code>
      or
      <em class="replaceable">
       <code>
        YYYYMMDDhhmmss
       </code>
      </em>
      format, depending on
          whether the function is used in string or numeric context.
     </p>
     <p>
      If the
      <em class="replaceable">
       <code>
        fsp
       </code>
      </em>
      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.
     </p>
     <p>
      <a class="link" href="date-and-time-functions.html#function_sysdate">
       <code class="literal">
        SYSDATE()
       </code>
      </a>
      returns the time at
          which it executes. This differs from the behavior for
      <a class="link" href="date-and-time-functions.html#function_now">
       <code class="literal">
        NOW()
       </code>
      </a>
      , which returns a constant
          time that indicates the time at which the statement began to
          execute. (Within a stored function or trigger,
      <a class="link" href="date-and-time-functions.html#function_now">
       <code class="literal">
        NOW()
       </code>
      </a>
      returns the time at which
          the function or triggering statement began to execute.)
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa19015521"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">NOW</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">SLEEP</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">NOW</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> NOW()               <span class="token punctuation">|</span> SLEEP(2) <span class="token punctuation">|</span> NOW()               <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 2006<span class="token punctuation">-</span>04<span class="token punctuation">-</span>12 13:47:36 <span class="token punctuation">|</span>        0 <span class="token punctuation">|</span> 2006<span class="token punctuation">-</span>04<span class="token punctuation">-</span>12 13:47:36 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">SYSDATE</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">SLEEP</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">SYSDATE</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> SYSDATE()           <span class="token punctuation">|</span> SLEEP(2) <span class="token punctuation">|</span> SYSDATE()           <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 2006<span class="token punctuation">-</span>04<span class="token punctuation">-</span>12 13:47:44 <span class="token punctuation">|</span>        0 <span class="token punctuation">|</span> 2006<span class="token punctuation">-</span>04<span class="token punctuation">-</span>12 13:47:46 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
     </div>
     <p>
      In addition, the
      <code class="literal">
       SET TIMESTAMP
      </code>
      statement
          affects the value returned by
      <a class="link" href="date-and-time-functions.html#function_now">
       <code class="literal">
        NOW()
       </code>
      </a>
      but not by
      <a class="link" href="date-and-time-functions.html#function_sysdate">
       <code class="literal">
        SYSDATE()
       </code>
      </a>
      . This means that
          timestamp settings in the binary log have no effect on
          invocations of
      <a class="link" href="date-and-time-functions.html#function_sysdate">
       <code class="literal">
        SYSDATE()
       </code>
      </a>
      .
     </p>
     <p>
      Because
      <a class="link" href="date-and-time-functions.html#function_sysdate">
       <code class="literal">
        SYSDATE()
       </code>
      </a>
      can return
          different values even within the same statement, and is not
          affected by
      <code class="literal">
       SET TIMESTAMP
      </code>
      , it is
          nondeterministic and therefore unsafe for replication if
          statement-based binary logging is used. If that is a problem,
          you can use row-based logging.
     </p>
     <p>
      Alternatively, you can use the
      <a class="link" href="server-options.html#option_mysqld_sysdate-is-now">
       <code class="option">
        --sysdate-is-now
       </code>
      </a>
      option to
          cause
      <a class="link" href="date-and-time-functions.html#function_sysdate">
       <code class="literal">
        SYSDATE()
       </code>
      </a>
      to be an alias
          for
      <a class="link" href="date-and-time-functions.html#function_now">
       <code class="literal">
        NOW()
       </code>
      </a>
      . This works if the
          option is used on both the replication source server and the
          replica.
     </p>
     <p>
      The nondeterministic nature of
      <a class="link" href="date-and-time-functions.html#function_sysdate">
       <code class="literal">
        SYSDATE()
       </code>
      </a>
      also means that
          indexes cannot be used for evaluating expressions that refer
          to it.
     </p>
    </li>
    <li class="listitem">
     <a name="function_time">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_time">
       <code class="literal">
        TIME(
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204328848">
     </a>
     <p>
      Extracts the time part of the time or datetime expression
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      and returns it as a string.
          Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      This function is unsafe for statement-based replication. A
          warning is logged if you use this function when
      <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format">
       <code class="literal">
        binlog_format
       </code>
      </a>
      is set to
      <code class="literal">
       STATEMENT
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa92297113"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TIME</span><span class="token punctuation">(</span><span class="token string">'2003-12-31 01:02:03'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'01:02:03'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TIME</span><span class="token punctuation">(</span><span class="token string">'2003-12-31 01:02:03.000123'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'01:02:03.000123'</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_timediff">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_timediff">
       <code class="literal">
        TIMEDIFF(
        <em class="replaceable">
         <code>
          expr1
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          expr2
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204312512">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_timediff">
       <code class="literal">
        TIMEDIFF()
       </code>
      </a>
      returns
      <em class="replaceable">
       <code>
        expr1
       </code>
      </em>
      −
      <em class="replaceable">
       <code>
        expr2
       </code>
      </em>
      expressed as a time value.
      <em class="replaceable">
       <code>
        expr1
       </code>
      </em>
      and
      <em class="replaceable">
       <code>
        expr2
       </code>
      </em>
      are strings which are
          converted to
      <code class="literal">
       TIME
      </code>
      or
      <code class="literal">
       DATETIME
      </code>
      expressions; these must be of the
          same type following conversion. Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        expr1
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        expr2
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      The result returned by
      <code class="literal">
       TIMEDIFF()
      </code>
      is
          limited to the range allowed for
      <a class="link" href="time.html" title="13.2.3 The TIME Type">
       <code class="literal">
        TIME
       </code>
      </a>
      values. Alternatively, you
          can use either of the functions
      <a class="link" href="date-and-time-functions.html#function_timestampdiff">
       <code class="literal">
        TIMESTAMPDIFF()
       </code>
      </a>
      and
      <a class="link" href="date-and-time-functions.html#function_unix-timestamp">
       <code class="literal">
        UNIX_TIMESTAMP()
       </code>
      </a>
      , both of which
          return integers.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa53272657"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TIMEDIFF</span><span class="token punctuation">(</span><span class="token string">'2000-01-01 00:00:00'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>                 <span class="token string">'2000-01-01 00:00:00.000001'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'-00:00:00.000001'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TIMEDIFF</span><span class="token punctuation">(</span><span class="token string">'2008-12-31 23:59:59.000001'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>                 <span class="token string">'2008-12-30 01:01:01.000002'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'46:58:57.999999'</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_timestamp">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_timestamp">
       <code class="literal">
        TIMESTAMP(
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        )
       </code>
      </a>
      ,
      <a class="link" href="date-and-time-functions.html#function_timestamp">
       <code class="literal">
        TIMESTAMP(
        <em class="replaceable">
         <code>
          expr1
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          expr2
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204286000">
     </a>
     <p>
      With a single argument, this function returns the date or
          datetime expression
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      as a
          datetime value. With two arguments, it adds the time
          expression
      <em class="replaceable">
       <code>
        expr2
       </code>
      </em>
      to the date or
          datetime expression
      <em class="replaceable">
       <code>
        expr1
       </code>
      </em>
      and
          returns the result as a datetime value. Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      ,
      <em class="replaceable">
       <code>
        expr1
       </code>
      </em>
      , or
      <em class="replaceable">
       <code>
        expr2
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa45212270"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TIMESTAMP</span><span class="token punctuation">(</span><span class="token string">'2003-12-31'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2003-12-31 00:00:00'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TIMESTAMP</span><span class="token punctuation">(</span><span class="token string">'2003-12-31 12:00:00'</span><span class="token punctuation">,</span><span class="token string">'12:00:00'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2004-01-01 00:00:00'</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_timestampadd">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_timestampadd">
       <code class="literal">
        TIMESTAMPADD(
        <em class="replaceable">
         <code>
          unit
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          interval
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          datetime_expr
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204269760">
     </a>
     <p>
      Adds the integer expression
      <em class="replaceable">
       <code>
        interval
       </code>
      </em>
      to the date or datetime
          expression
      <em class="replaceable">
       <code>
        datetime_expr
       </code>
      </em>
      . The unit
          for
      <em class="replaceable">
       <code>
        interval
       </code>
      </em>
      is given by the
      <em class="replaceable">
       <code>
        unit
       </code>
      </em>
      argument, which should be one
          of the following values:
      <code class="literal">
       MICROSECOND
      </code>
      (microseconds),
      <code class="literal">
       SECOND
      </code>
      ,
      <code class="literal">
       MINUTE
      </code>
      ,
      <code class="literal">
       HOUR
      </code>
      ,
      <code class="literal">
       DAY
      </code>
      ,
      <code class="literal">
       WEEK
      </code>
      ,
      <code class="literal">
       MONTH
      </code>
      ,
      <code class="literal">
       QUARTER
      </code>
      , or
      <code class="literal">
       YEAR
      </code>
      .
     </p>
     <p>
      The
      <em class="replaceable">
       <code>
        unit
       </code>
      </em>
      value may be specified
          using one of keywords as shown, or with a prefix of
      <code class="literal">
       SQL_TSI_
      </code>
      . For example,
      <code class="literal">
       DAY
      </code>
      and
      <code class="literal">
       SQL_TSI_DAY
      </code>
      both
          are legal.
     </p>
     <p>
      This function returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        interval
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        datetime_expr
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa36184224"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TIMESTAMPADD</span><span class="token punctuation">(</span><span class="token keyword">MINUTE</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">'2003-01-02'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2003-01-02 00:01:00'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TIMESTAMPADD</span><span class="token punctuation">(</span><span class="token keyword">WEEK</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token string">'2003-01-02'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2003-01-09'</span></code></pre>
     </div>
     <p>
      When adding a
      <code class="literal">
       MONTH
      </code>
      interval to a
      <code class="literal">
       DATE
      </code>
      or
      <code class="literal">
       DATETIME
      </code>
      value,
          and the resulting date includes a day that does not exist in
          the given month, the day is adjusted to the last day of the
          month, as shown here:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa87426126"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TIMESTAMPADD</span><span class="token punctuation">(</span><span class="token keyword">MONTH</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token datatype">DATE</span> <span class="token string">'2024-03-30'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> t1<span class="token punctuation">,</span> 
     <span class="token operator">&gt;</span>        <span class="token function">TIMESTAMPADD</span><span class="token punctuation">(</span><span class="token keyword">MONTH</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token datatype">DATE</span> <span class="token string">'2024-03-31'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> t2<span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> t1         <span class="token punctuation">|</span> t2         <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 2024<span class="token punctuation">-</span>04<span class="token punctuation">-</span>30 <span class="token punctuation">|</span> 2024<span class="token punctuation">-</span>04<span class="token punctuation">-</span>30 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">1 row in set (0.00 sec)</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_timestampdiff">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_timestampdiff">
       <code class="literal">
        TIMESTAMPDIFF(
        <em class="replaceable">
         <code>
          unit
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          datetime_expr1
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          datetime_expr2
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204238368">
     </a>
     <p>
      Returns
      <em class="replaceable">
       <code>
        datetime_expr2
       </code>
      </em>
      −
      <em class="replaceable">
       <code>
        datetime_expr1
       </code>
      </em>
      , where
      <em class="replaceable">
       <code>
        datetime_expr1
       </code>
      </em>
      and
      <em class="replaceable">
       <code>
        datetime_expr2
       </code>
      </em>
      are date or datetime
          expressions. One expression may be a date and the other a
          datetime; a date value is treated as a datetime having the
          time part
      <code class="literal">
       '00:00:00'
      </code>
      where necessary. The
          unit for the result (an integer) is given by the
      <em class="replaceable">
       <code>
        unit
       </code>
      </em>
      argument. The legal values for
      <em class="replaceable">
       <code>
        unit
       </code>
      </em>
      are the same as those listed
          in the description of the
      <a class="link" href="date-and-time-functions.html#function_timestampadd">
       <code class="literal">
        TIMESTAMPADD()
       </code>
      </a>
      function.
     </p>
     <p>
      This function returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        datetime_expr1
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        datetime_expr2
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa15878912"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TIMESTAMPDIFF</span><span class="token punctuation">(</span><span class="token keyword">MONTH</span><span class="token punctuation">,</span><span class="token string">'2003-02-01'</span><span class="token punctuation">,</span><span class="token string">'2003-05-01'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">3</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TIMESTAMPDIFF</span><span class="token punctuation">(</span><span class="token datatype">YEAR</span><span class="token punctuation">,</span><span class="token string">'2002-05-01'</span><span class="token punctuation">,</span><span class="token string">'2001-01-01'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token operator">-</span><span class="token number">1</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TIMESTAMPDIFF</span><span class="token punctuation">(</span><span class="token keyword">MINUTE</span><span class="token punctuation">,</span><span class="token string">'2003-02-01'</span><span class="token punctuation">,</span><span class="token string">'2003-05-01 12:05:55'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">128885</span></code></pre>
     </div>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       The order of the date or datetime arguments for this
            function is the opposite of that used with the
       <a class="link" href="date-and-time-functions.html#function_timestamp">
        <code class="literal">
         TIMESTAMP()
        </code>
       </a>
       function when
            invoked with 2 arguments.
      </p>
     </div>
    </li>
    <li class="listitem">
     <a name="function_time-format">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_time-format">
       <code class="literal">
        TIME_FORMAT(
        <em class="replaceable">
         <code>
          time
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          format
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204216336">
     </a>
     <p>
      This is used like the
      <a class="link" href="date-and-time-functions.html#function_date-format">
       <code class="literal">
        DATE_FORMAT()
       </code>
      </a>
      function, but the
      <em class="replaceable">
       <code>
        format
       </code>
      </em>
      string may contain format
          specifiers only for hours, minutes, seconds, and microseconds.
          Other specifiers produce a
      <code class="literal">
       NULL
      </code>
      or
      <code class="literal">
       0
      </code>
      .
      <code class="literal">
       TIME_FORMAT()
      </code>
      returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        time
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        format
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      If the
      <em class="replaceable">
       <code>
        time
       </code>
      </em>
      value contains an hour
          part that is greater than
      <code class="literal">
       23
      </code>
      , the
      <code class="literal">
       %H
      </code>
      and
      <code class="literal">
       %k
      </code>
      hour format
          specifiers produce a value larger than the usual range of
      <code class="literal">
       0..23
      </code>
      . The other hour format specifiers
          produce the hour value modulo 12.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa67819064"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TIME_FORMAT</span><span class="token punctuation">(</span><span class="token string">'100:00:00'</span><span class="token punctuation">,</span> <span class="token string">'%H %k %h %I %l'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'100 100 04 04 4'</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_time-to-sec">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_time-to-sec">
       <code class="literal">
        TIME_TO_SEC(
        <em class="replaceable">
         <code>
          time
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204196016">
     </a>
     <p>
      Returns the
      <em class="replaceable">
       <code>
        time
       </code>
      </em>
      argument,
          converted to seconds. Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        time
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa22372863"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TIME_TO_SEC</span><span class="token punctuation">(</span><span class="token string">'22:23:00'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">80580</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TIME_TO_SEC</span><span class="token punctuation">(</span><span class="token string">'00:39:38'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">2378</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_to-days">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_to-days">
       <code class="literal">
        TO_DAYS(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204182768">
     </a>
     <p>
      Given a date
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      , returns a day
          number (the number of days since year 0). Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa16561339"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TO_DAYS</span><span class="token punctuation">(</span><span class="token number">950501</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">728779</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TO_DAYS</span><span class="token punctuation">(</span><span class="token string">'2007-10-07'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">733321</span></code></pre>
     </div>
     <p>
      <a class="link" href="date-and-time-functions.html#function_to-days">
       <code class="literal">
        TO_DAYS()
       </code>
      </a>
      is not intended for
          use with values that precede the advent of the Gregorian
          calendar (1582), because it does not take into account the
          days that were lost when the calendar was changed. For dates
          before 1582 (and possibly a later year in other locales),
          results from this function are not reliable. See
      <a class="xref" href="mysql-calendar.html" title="13.2.7 What Calendar Is Used By MySQL?">
       Section 13.2.7, “What Calendar Is Used By MySQL?”
      </a>
      , for details.
     </p>
     <p>
      Remember that MySQL converts two-digit year values in dates to
          four-digit form using the rules in
      <a class="xref" href="date-and-time-types.html" title="13.2 Date and Time Data Types">
       Section 13.2, “Date and Time Data Types”
      </a>
      . For example,
      <code class="literal">
       '2008-10-07'
      </code>
      and
      <code class="literal">
       '08-10-07'
      </code>
      are seen as identical dates:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa28663557"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TO_DAYS</span><span class="token punctuation">(</span><span class="token string">'2008-10-07'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">TO_DAYS</span><span class="token punctuation">(</span><span class="token string">'08-10-07'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">733687</span><span class="token punctuation">,</span> <span class="token number">733687</span></code></pre>
     </div>
     <p>
      In MySQL, the zero date is defined as
      <code class="literal">
       '0000-00-00'
      </code>
      , even though this date is
          itself considered invalid. This means that, for
      <code class="literal">
       '0000-00-00'
      </code>
      and
      <code class="literal">
       '0000-01-01'
      </code>
      ,
      <a class="link" href="date-and-time-functions.html#function_to-days">
       <code class="literal">
        TO_DAYS()
       </code>
      </a>
      returns the values
          shown here:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa72755812"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TO_DAYS</span><span class="token punctuation">(</span><span class="token string">'0000-00-00'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> to_days('0000<span class="token punctuation">-</span>00<span class="token punctuation">-</span>00') <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>                  NULL <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">1 row in set, 1 warning (0.00 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">WARNINGS</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Level   <span class="token punctuation">|</span> Code <span class="token punctuation">|</span> Message                                <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Warning <span class="token punctuation">|</span> 1292 <span class="token punctuation">|</span> Incorrect datetime value: '0000<span class="token punctuation">-</span>00<span class="token punctuation">-</span>00' <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">1 row in set (0.00 sec)</span>


<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TO_DAYS</span><span class="token punctuation">(</span><span class="token string">'0000-01-01'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> to_days('0000<span class="token punctuation">-</span>01<span class="token punctuation">-</span>01') <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>                     1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">1 row in set (0.00 sec)</span></code></pre>
     </div>
     <p>
      This is true whether or not the
      <a class="link" href="sql-mode.html#sqlmode_allow_invalid_dates">
       <code class="literal">
        ALLOW_INVALID_DATES
       </code>
      </a>
      SQL
          server mode is enabled.
     </p>
    </li>
    <li class="listitem">
     <a name="function_to-seconds">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_to-seconds">
       <code class="literal">
        TO_SECONDS(
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204152432">
     </a>
     <p>
      Given a date or datetime
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      ,
          returns the number of seconds since the year 0. If
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      is not a valid date or
          datetime value (including
      <code class="literal">
       NULL
      </code>
      ), it returns
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa23540102"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TO_SECONDS</span><span class="token punctuation">(</span><span class="token number">950501</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">62966505600</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TO_SECONDS</span><span class="token punctuation">(</span><span class="token string">'2009-11-29'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">63426672000</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TO_SECONDS</span><span class="token punctuation">(</span><span class="token string">'2009-11-29 13:43:32'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">63426721412</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TO_SECONDS</span><span class="token punctuation">(</span> <span class="token function">NOW</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">63426721458</span></code></pre>
     </div>
     <p>
      Like
      <a class="link" href="date-and-time-functions.html#function_to-days">
       <code class="literal">
        TO_DAYS()
       </code>
      </a>
      ,
      <code class="literal">
       TO_SECONDS()
      </code>
      is not intended for use with
          values that precede the advent of the Gregorian calendar
          (1582), because it does not take into account the days that
          were lost when the calendar was changed. For dates before 1582
          (and possibly a later year in other locales), results from
          this function are not reliable. See
      <a class="xref" href="mysql-calendar.html" title="13.2.7 What Calendar Is Used By MySQL?">
       Section 13.2.7, “What Calendar Is Used By MySQL?”
      </a>
      , for details.
     </p>
     <p>
      Like
      <a class="link" href="date-and-time-functions.html#function_to-days">
       <code class="literal">
        TO_DAYS()
       </code>
      </a>
      ,
      <code class="literal">
       TO_SECONDS()
      </code>
      , converts two-digit year
          values in dates to four-digit form using the rules in
      <a class="xref" href="date-and-time-types.html" title="13.2 Date and Time Data Types">
       Section 13.2, “Date and Time Data Types”
      </a>
      .
     </p>
     <p>
      In MySQL, the zero date is defined as
      <code class="literal">
       '0000-00-00'
      </code>
      , even though this date is
          itself considered invalid. This means that, for
      <code class="literal">
       '0000-00-00'
      </code>
      and
      <code class="literal">
       '0000-01-01'
      </code>
      ,
      <a class="link" href="date-and-time-functions.html#function_to-seconds">
       <code class="literal">
        TO_SECONDS()
       </code>
      </a>
      returns the values
          shown here:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa90581470"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TO_SECONDS</span><span class="token punctuation">(</span><span class="token string">'0000-00-00'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> TO_SECONDS('0000<span class="token punctuation">-</span>00<span class="token punctuation">-</span>00') <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>                     NULL <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">1 row in set, 1 warning (0.00 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">WARNINGS</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Level   <span class="token punctuation">|</span> Code <span class="token punctuation">|</span> Message                                <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Warning <span class="token punctuation">|</span> 1292 <span class="token punctuation">|</span> Incorrect datetime value: '0000<span class="token punctuation">-</span>00<span class="token punctuation">-</span>00' <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">1 row in set (0.00 sec)</span>


<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">TO_SECONDS</span><span class="token punctuation">(</span><span class="token string">'0000-01-01'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> TO_SECONDS('0000<span class="token punctuation">-</span>01<span class="token punctuation">-</span>01') <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>                    86400 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">1 row in set (0.00 sec)</span></code></pre>
     </div>
     <p>
      This is true whether or not the
      <a class="link" href="sql-mode.html#sqlmode_allow_invalid_dates">
       <code class="literal">
        ALLOW_INVALID_DATES
       </code>
      </a>
      SQL
          server mode is enabled.
     </p>
    </li>
    <li class="listitem">
     <a name="function_unix-timestamp">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_unix-timestamp">
       <code class="literal">
        UNIX_TIMESTAMP([
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        ])
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204120832">
     </a>
     <p>
      If
      <a class="link" href="date-and-time-functions.html#function_unix-timestamp">
       <code class="literal">
        UNIX_TIMESTAMP()
       </code>
      </a>
      is called
          with no
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      argument, it returns a
          Unix timestamp representing seconds since
      <code class="literal">
       '1970-01-01
          00:00:00'
      </code>
      UTC.
     </p>
     <p>
      If
      <a class="link" href="date-and-time-functions.html#function_unix-timestamp">
       <code class="literal">
        UNIX_TIMESTAMP()
       </code>
      </a>
      is called
          with a
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      argument, it returns
          the value of the argument as seconds since
      <code class="literal">
       '1970-01-01 00:00:00'
      </code>
      UTC. The server
          interprets
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      as a value in the
          session time zone and converts it to an internal Unix
          timestamp value in UTC. (Clients can set the session time zone
          as described in
      <a class="xref" href="time-zone-support.html" title="7.1.15 MySQL Server Time Zone Support">
       Section 7.1.15, “MySQL Server Time Zone Support”
      </a>
      .) The
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      argument may be a
      <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
       <code class="literal">
        DATE
       </code>
      </a>
      ,
      <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
       <code class="literal">
        DATETIME
       </code>
      </a>
      , or
      <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
       <code class="literal">
        TIMESTAMP
       </code>
      </a>
      string, or a number
          in
      <em class="replaceable">
       <code>
        YYMMDD
       </code>
      </em>
      ,
      <em class="replaceable">
       <code>
        YYMMDDhhmmss
       </code>
      </em>
      ,
      <em class="replaceable">
       <code>
        YYYYMMDD
       </code>
      </em>
      , or
      <em class="replaceable">
       <code>
        YYYYMMDDhhmmss
       </code>
      </em>
      format. If the
          argument includes a time part, it may optionally include a
          fractional seconds part.
     </p>
     <p>
      The return value is an integer if no argument is given or the
          argument does not include a fractional seconds part, or
      <a class="link" href="fixed-point-types.html" title="13.1.3 Fixed-Point Types (Exact Value) - DECIMAL, NUMERIC">
       <code class="literal">
        DECIMAL
       </code>
      </a>
      if an argument is given
          that includes a fractional seconds part.
     </p>
     <p>
      When the
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      argument is a
      <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
       <code class="literal">
        TIMESTAMP
       </code>
      </a>
      column,
      <a class="link" href="date-and-time-functions.html#function_unix-timestamp">
       <code class="literal">
        UNIX_TIMESTAMP()
       </code>
      </a>
      returns the
          internal timestamp value directly, with no implicit
      <span class="quote">
       “
       <span class="quote">
        string-to-Unix-timestamp
       </span>
       ”
      </span>
      conversion.
     </p>
     <p>
      The valid range of argument values is the same as for the
      <a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
       <code class="literal">
        TIMESTAMP
       </code>
      </a>
      data type:
      <code class="literal">
       '1970-01-01 00:00:01.000000'
      </code>
      UTC to
      <code class="literal">
       '2038-01-19 03:14:07.999999'
      </code>
      UTC for 32-bit
          platforms; for MySQL running on 64-bit platforms, the valid
          range of argument values for
      <code class="literal">
       UNIX_TIMESTAMP()
      </code>
      is
      <code class="literal">
       '1970-01-01
          00:00:01.000000'
      </code>
      UTC to
      <code class="literal">
       '3001-01-19
          03:14:07.999999'
      </code>
      UTC (corresponding to
          32536771199.999999 seconds).
     </p>
     <p>
      Regardless of MySQL version or platform architecture, if you
          pass an out-of-range date to
      <a class="link" href="date-and-time-functions.html#function_unix-timestamp">
       <code class="literal">
        UNIX_TIMESTAMP()
       </code>
      </a>
      , it returns
      <code class="literal">
       0
      </code>
      . If
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      , it returns
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa94937673"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">UNIX_TIMESTAMP</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">1447431666</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">UNIX_TIMESTAMP</span><span class="token punctuation">(</span><span class="token string">'2015-11-13 10:20:19'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">1447431619</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">UNIX_TIMESTAMP</span><span class="token punctuation">(</span><span class="token string">'2015-11-13 10:20:19.012'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">1447431619.012</span></code></pre>
     </div>
     <a class="indexterm" name="idm46045204085520">
     </a>
     <p>
      If you use
      <a class="link" href="date-and-time-functions.html#function_unix-timestamp">
       <code class="literal">
        UNIX_TIMESTAMP()
       </code>
      </a>
      and
      <a class="link" href="date-and-time-functions.html#function_from-unixtime">
       <code class="literal">
        FROM_UNIXTIME()
       </code>
      </a>
      to convert
          between values in a non-UTC time zone and Unix timestamp
          values, the conversion is lossy because the mapping is not
          one-to-one in both directions. For example, due to conventions
          for local time zone changes such as Daylight Saving Time
          (DST), it is possible for
      <a class="link" href="date-and-time-functions.html#function_unix-timestamp">
       <code class="literal">
        UNIX_TIMESTAMP()
       </code>
      </a>
      to map two
          values that are distinct in a non-UTC time zone to the same
          Unix timestamp value.
      <a class="link" href="date-and-time-functions.html#function_from-unixtime">
       <code class="literal">
        FROM_UNIXTIME()
       </code>
      </a>
      maps that value
          back to only one of the original values. Here is an example,
          using values that are distinct in the
      <code class="literal">
       MET
      </code>
      time zone:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa2565946"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> time_zone <span class="token operator">=</span> <span class="token string">'MET'</span><span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">UNIX_TIMESTAMP</span><span class="token punctuation">(</span><span class="token string">'2005-03-27 03:00:00'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> UNIX_TIMESTAMP('2005<span class="token punctuation">-</span>03<span class="token punctuation">-</span>27 03:00:00') <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>                            1111885200 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">UNIX_TIMESTAMP</span><span class="token punctuation">(</span><span class="token string">'2005-03-27 02:00:00'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> UNIX_TIMESTAMP('2005<span class="token punctuation">-</span>03<span class="token punctuation">-</span>27 02:00:00') <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>                            1111885200 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">FROM_UNIXTIME</span><span class="token punctuation">(</span><span class="token number">1111885200</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> FROM_UNIXTIME(1111885200) <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 2005<span class="token punctuation">-</span>03<span class="token punctuation">-</span>27 03:00:00       <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
     </div>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       To use named time zones such as
       <code class="literal">
        'MET'
       </code>
       or
       <code class="literal">
        'Europe/Amsterdam'
       </code>
       , the time zone tables
            must be properly set up. For instructions, see
       <a class="xref" href="time-zone-support.html" title="7.1.15 MySQL Server Time Zone Support">
        Section 7.1.15, “MySQL Server Time Zone Support”
       </a>
       .
      </p>
     </div>
     <p>
      If you want to subtract
      <a class="link" href="date-and-time-functions.html#function_unix-timestamp">
       <code class="literal">
        UNIX_TIMESTAMP()
       </code>
      </a>
      columns, you
          might want to cast them to signed integers. See
      <a class="xref" href="cast-functions.html" title="14.10 Cast Functions and Operators">
       Section 14.10, “Cast Functions and Operators”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_utc-date">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_utc-date">
       <code class="literal">
        UTC_DATE
       </code>
      </a>
      ,
      <a class="link" href="date-and-time-functions.html#function_utc-date">
       <code class="literal">
        UTC_DATE()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204061840">
     </a>
     <p>
      Returns the current UTC date as a value in
      <code class="literal">
       '
       <em class="replaceable">
        <code>
         YYYY-MM-DD
        </code>
       </em>
       '
      </code>
      or
      <em class="replaceable">
       <code>
        YYYYMMDD
       </code>
      </em>
      format, depending on
          whether the function is used in string or numeric context.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa48893208"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">UTC_DATE</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">UTC_DATE</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2003-08-14'</span><span class="token punctuation">,</span> <span class="token number">20030814</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_utc-time">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_utc-time">
       <code class="literal">
        UTC_TIME
       </code>
      </a>
      ,
      <a class="link" href="date-and-time-functions.html#function_utc-time">
       <code class="literal">
        UTC_TIME([
        <em class="replaceable">
         <code>
          fsp
         </code>
        </em>
        ])
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204048768">
     </a>
     <p>
      Returns the current UTC time as a value in
      <em class="replaceable">
       <code>
        'hh:mm:ss'
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        hhmmss
       </code>
      </em>
      format, depending on whether
          the function is used in string or numeric context.
     </p>
     <p>
      If the
      <em class="replaceable">
       <code>
        fsp
       </code>
      </em>
      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.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa19225327"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">UTC_TIME</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">UTC_TIME</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'18:07:53'</span><span class="token punctuation">,</span> <span class="token number">180753.000000</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_utc-timestamp">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_utc-timestamp">
       <code class="literal">
        UTC_TIMESTAMP
       </code>
      </a>
      ,
      <a class="link" href="date-and-time-functions.html#function_utc-timestamp">
       <code class="literal">
        UTC_TIMESTAMP([
        <em class="replaceable">
         <code>
          fsp
         </code>
        </em>
        ])
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204035360">
     </a>
     <p>
      Returns the current UTC date and time as a value in
      <code class="literal">
       '
       <em class="replaceable">
        <code>
         YYYY-MM-DD
          hh:mm:ss
        </code>
       </em>
       '
      </code>
      or
      <em class="replaceable">
       <code>
        YYYYMMDDhhmmss
       </code>
      </em>
      format, depending on
          whether the function is used in string or numeric context.
     </p>
     <p>
      If the
      <em class="replaceable">
       <code>
        fsp
       </code>
      </em>
      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.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa58416067"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">UTC_TIMESTAMP</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">UTC_TIMESTAMP</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'2003-08-14 18:08:04'</span><span class="token punctuation">,</span> <span class="token number">20030814180804.000000</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_week">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_week">
       <code class="literal">
        WEEK(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        [,
        <em class="replaceable">
         <code>
          mode
         </code>
        </em>
        ])
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045204021984">
     </a>
     <p>
      This function returns the week number for
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      . The two-argument form of
      <a class="link" href="date-and-time-functions.html#function_week">
       <code class="literal">
        WEEK()
       </code>
      </a>
      enables you to specify
          whether the week starts on Sunday or Monday and whether the
          return value should be in the range from
      <code class="literal">
       0
      </code>
      to
      <code class="literal">
       53
      </code>
      or from
      <code class="literal">
       1
      </code>
      to
      <code class="literal">
       53
      </code>
      . If the
      <em class="replaceable">
       <code>
        mode
       </code>
      </em>
      argument is omitted, the value of the
      <a class="link" href="server-system-variables.html#sysvar_default_week_format">
       <code class="literal">
        default_week_format
       </code>
      </a>
      system
          variable is used. See
      <a class="xref" href="server-system-variables.html" title="7.1.8 Server System Variables">
       Section 7.1.8, “Server System Variables”
      </a>
      . For a
      <code class="literal">
       NULL
      </code>
      date value, the function returns
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      The following table describes how the
      <em class="replaceable">
       <code>
        mode
       </code>
      </em>
      argument works.
     </p>
     <div class="informaltable">
      <table summary="Now the mode argument of the WEEK function works. For each mode value, the table lists the first day of the week, the range, and a description of week 1.">
       <colgroup>
        <col style="width: 10%"/>
        <col style="width: 20%"/>
        <col style="width: 20%"/>
        <col style="width: 50%"/>
       </colgroup>
       <thead>
        <tr>
         <th scope="col">
          Mode
         </th>
         <th scope="col">
          First day of week
         </th>
         <th scope="col">
          Range
         </th>
         <th scope="col">
          Week 1 is the first week …
         </th>
        </tr>
       </thead>
       <tbody>
        <tr>
         <th scope="row">
          0
         </th>
         <td>
          Sunday
         </td>
         <td>
          0-53
         </td>
         <td>
          with a Sunday in this year
         </td>
        </tr>
        <tr>
         <th scope="row">
          1
         </th>
         <td>
          Monday
         </td>
         <td>
          0-53
         </td>
         <td>
          with 4 or more days this year
         </td>
        </tr>
        <tr>
         <th scope="row">
          2
         </th>
         <td>
          Sunday
         </td>
         <td>
          1-53
         </td>
         <td>
          with a Sunday in this year
         </td>
        </tr>
        <tr>
         <th scope="row">
          3
         </th>
         <td>
          Monday
         </td>
         <td>
          1-53
         </td>
         <td>
          with 4 or more days this year
         </td>
        </tr>
        <tr>
         <th scope="row">
          4
         </th>
         <td>
          Sunday
         </td>
         <td>
          0-53
         </td>
         <td>
          with 4 or more days this year
         </td>
        </tr>
        <tr>
         <th scope="row">
          5
         </th>
         <td>
          Monday
         </td>
         <td>
          0-53
         </td>
         <td>
          with a Monday in this year
         </td>
        </tr>
        <tr>
         <th scope="row">
          6
         </th>
         <td>
          Sunday
         </td>
         <td>
          1-53
         </td>
         <td>
          with 4 or more days this year
         </td>
        </tr>
        <tr>
         <th scope="row">
          7
         </th>
         <td>
          Monday
         </td>
         <td>
          1-53
         </td>
         <td>
          with a Monday in this year
         </td>
        </tr>
       </tbody>
      </table>
     </div>
     <p>
      For
      <em class="replaceable">
       <code>
        mode
       </code>
      </em>
      values with a meaning of
      <span class="quote">
       “
       <span class="quote">
        with 4 or more days this year,
       </span>
       ”
      </span>
      weeks are
          numbered according to ISO 8601:1988:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         If the week containing January 1 has 4 or more days in the
              new year, it is week 1.
        </p>
       </li>
       <li class="listitem">
        <p>
         Otherwise, it is the last week of the previous year, and
              the next week is week 1.
        </p>
       </li>
      </ul>
     </div>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa33528828"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">WEEK</span><span class="token punctuation">(</span><span class="token string">'2008-02-20'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">7</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">WEEK</span><span class="token punctuation">(</span><span class="token string">'2008-02-20'</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">7</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">WEEK</span><span class="token punctuation">(</span><span class="token string">'2008-02-20'</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">8</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">WEEK</span><span class="token punctuation">(</span><span class="token string">'2008-12-31'</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">53</span></code></pre>
     </div>
     <p>
      If a date falls in the last week of the previous year, MySQL
          returns
      <code class="literal">
       0
      </code>
      if you do not use
      <code class="literal">
       2
      </code>
      ,
      <code class="literal">
       3
      </code>
      ,
      <code class="literal">
       6
      </code>
      , or
      <code class="literal">
       7
      </code>
      as the optional
      <em class="replaceable">
       <code>
        mode
       </code>
      </em>
      argument:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa96160951"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">YEAR</span><span class="token punctuation">(</span><span class="token string">'2000-01-01'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">WEEK</span><span class="token punctuation">(</span><span class="token string">'2000-01-01'</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">2000</span><span class="token punctuation">,</span> <span class="token number">0</span></code></pre>
     </div>
     <p>
      One might argue that
      <a class="link" href="date-and-time-functions.html#function_week">
       <code class="literal">
        WEEK()
       </code>
      </a>
      should return
      <code class="literal">
       52
      </code>
      because the given date
          actually occurs in the 52nd week of 1999.
      <a class="link" href="date-and-time-functions.html#function_week">
       <code class="literal">
        WEEK()
       </code>
      </a>
      returns
      <code class="literal">
       0
      </code>
      instead so that the return value is
      <span class="quote">
       “
       <span class="quote">
        the week number in the given year.
       </span>
       ”
      </span>
      This makes
          use of the
      <a class="link" href="date-and-time-functions.html#function_week">
       <code class="literal">
        WEEK()
       </code>
      </a>
      function
          reliable when combined with other functions that extract a
          date part from a date.
     </p>
     <p>
      If you prefer a result evaluated with respect to the year that
          contains the first day of the week for the given date, use
      <code class="literal">
       0
      </code>
      ,
      <code class="literal">
       2
      </code>
      ,
      <code class="literal">
       5
      </code>
      , or
      <code class="literal">
       7
      </code>
      as the optional
      <em class="replaceable">
       <code>
        mode
       </code>
      </em>
      argument.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa60907367"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">WEEK</span><span class="token punctuation">(</span><span class="token string">'2000-01-01'</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">52</span></code></pre>
     </div>
     <p>
      Alternatively, use the
      <a class="link" href="date-and-time-functions.html#function_yearweek">
       <code class="literal">
        YEARWEEK()
       </code>
      </a>
      function:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa35361472"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">YEARWEEK</span><span class="token punctuation">(</span><span class="token string">'2000-01-01'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">199952</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">MID</span><span class="token punctuation">(</span><span class="token function">YEARWEEK</span><span class="token punctuation">(</span><span class="token string">'2000-01-01'</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'52'</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_weekday">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_weekday">
       <code class="literal">
        WEEKDAY(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045203931616">
     </a>
     <p>
      Returns the weekday index for
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      (
      <code class="literal">
       0
      </code>
      = Monday,
      <code class="literal">
       1
      </code>
      =
          Tuesday, …
      <code class="literal">
       6
      </code>
      = Sunday). Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa60092287"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">WEEKDAY</span><span class="token punctuation">(</span><span class="token string">'2008-02-03 22:23:00'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">6</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">WEEKDAY</span><span class="token punctuation">(</span><span class="token string">'2007-11-06'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">1</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_weekofyear">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_weekofyear">
       <code class="literal">
        WEEKOFYEAR(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045203916288">
     </a>
     <p>
      Returns the calendar week of the date as a number in the range
          from
      <code class="literal">
       1
      </code>
      to
      <code class="literal">
       53
      </code>
      . Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      <a class="link" href="date-and-time-functions.html#function_weekofyear">
       <code class="literal">
        WEEKOFYEAR()
       </code>
      </a>
      is a compatibility
          function that is equivalent to
      <a class="link" href="date-and-time-functions.html#function_week">
       <code class="literal">
        WEEK(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        ,3)
       </code>
      </a>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa29872639"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">WEEKOFYEAR</span><span class="token punctuation">(</span><span class="token string">'2008-02-20'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">8</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_year">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_year">
       <code class="literal">
        YEAR(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045203899472">
     </a>
     <p>
      Returns the year for
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      , in the
          range
      <code class="literal">
       1000
      </code>
      to
      <code class="literal">
       9999
      </code>
      , or
      <code class="literal">
       0
      </code>
      for the
      <span class="quote">
       “
       <span class="quote">
        zero
       </span>
       ”
      </span>
      date. Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa39209840"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">YEAR</span><span class="token punctuation">(</span><span class="token string">'1987-01-01'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">1987</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_yearweek">
     </a>
     <p>
      <a class="link" href="date-and-time-functions.html#function_yearweek">
       <code class="literal">
        YEARWEEK(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        )
       </code>
      </a>
      ,
      <a class="link" href="date-and-time-functions.html#function_yearweek">
       <code class="literal">
        YEARWEEK(
        <em class="replaceable">
         <code>
          date
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          mode
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045203882336">
     </a>
     <p>
      Returns year and week for a date. The year in the result may
          be different from the year in the date argument for the first
          and the last week of the year. Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        date
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      The
      <em class="replaceable">
       <code>
        mode
       </code>
      </em>
      argument works exactly
          like the
      <em class="replaceable">
       <code>
        mode
       </code>
      </em>
      argument to
      <a class="link" href="date-and-time-functions.html#function_week">
       <code class="literal">
        WEEK()
       </code>
      </a>
      . For the single-argument
          syntax, a
      <em class="replaceable">
       <code>
        mode
       </code>
      </em>
      value of 0 is used.
          Unlike
      <a class="link" href="date-and-time-functions.html#function_week">
       <code class="literal">
        WEEK()
       </code>
      </a>
      , the value of
      <a class="link" href="server-system-variables.html#sysvar_default_week_format">
       <code class="literal">
        default_week_format
       </code>
      </a>
      does not
          influence
      <a class="link" href="date-and-time-functions.html#function_yearweek">
       <code class="literal">
        YEARWEEK()
       </code>
      </a>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa81081390"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">YEARWEEK</span><span class="token punctuation">(</span><span class="token string">'1987-01-01'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">198652</span></code></pre>
     </div>
     <p>
      The week number is different from what the
      <a class="link" href="date-and-time-functions.html#function_week">
       <code class="literal">
        WEEK()
       </code>
      </a>
      function would return
          (
      <code class="literal">
       0
      </code>
      ) for optional arguments
      <code class="literal">
       0
      </code>
      or
      <code class="literal">
       1
      </code>
      , as
      <a class="link" href="date-and-time-functions.html#function_week">
       <code class="literal">
        WEEK()
       </code>
      </a>
      then returns the week in
          the context of the given year.
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
