doc-exports/docs/dli/sqlreference/dli_08_0066.html
Su, Xiaomeng 04d4597cf3 dli_sqlreference_0511_version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
Co-committed-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
2023-11-02 14:34:08 +00:00

208 lines
21 KiB
HTML

<a name="dli_08_0066"></a><a name="dli_08_0066"></a>
<h1 class="topictitle1">Date Functions</h1>
<div id="body8662426"><p id="dli_08_0066__en-us_topic_0093946912_a4eb9a9b304ea448e951ef2c47f18f371"><a href="#dli_08_0066__en-us_topic_0093946912_t47047d4480284fb3becd7b6d04352ec3">Table 1</a> lists the date functions supported in DLI.</p>
<div class="tablenoborder"><a name="dli_08_0066__en-us_topic_0093946912_t47047d4480284fb3becd7b6d04352ec3"></a><a name="en-us_topic_0093946912_t47047d4480284fb3becd7b6d04352ec3"></a><table cellpadding="4" cellspacing="0" summary="" id="dli_08_0066__en-us_topic_0093946912_t47047d4480284fb3becd7b6d04352ec3" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Date/time functions</caption><thead align="left"><tr id="dli_08_0066__en-us_topic_0093946912_r45aca931c8c54044afdb6da9d6f15edf"><th align="left" class="cellrowborder" valign="top" width="26.57%" id="mcps1.3.2.2.4.1.1"><p id="dli_08_0066__en-us_topic_0093946912_abfe0d47e35bc4affa014a47155c9bb56">Function</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="13.81%" id="mcps1.3.2.2.4.1.2"><p id="dli_08_0066__en-us_topic_0093946912_ac683ec8a51644d5594e147e17be71eb8">Return Type</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="59.62%" id="mcps1.3.2.2.4.1.3"><p id="dli_08_0066__en-us_topic_0093946912_a511f207accc748b390d97221bc2d70b5">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="dli_08_0066__en-us_topic_0093946912_rb5a8bd21ab874a9d877d9a13796d9e30"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_afbe11979abc04c60b0114c57f1d5c5d0">from_unixtime(bigint unixtime[, string format])</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_ad5e3f4d7c2c940b99876d5cf1572a69c">STRING</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__p7338101202810">Convert a timestamp to the time format "yyyy-MM-dd HH:mm:ss" or "yyyyMMddHHmmss.uuuuuu".</p>
<p id="dli_08_0066__en-us_topic_0093946912_a95bd4e7b181542f78eb78e1a62fab5e8">For example, select FROM_UNIXTIME(1608135036,'yyyy-MM-dd HH:mm:ss').</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_re2fd8c63d4ee428889e6cd380dd13d2c"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_a87bd755275e549ce9054ea92dfb03577">unix_timestamp()</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a3b73934e8e7c4ea8bea9c933aa2c4e89">BIGINT</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_afcd259de7089415ba352f1f8c2df3924">Return a Unix timestamp (the number of seconds that have elapsed since <span class="parmname" id="dli_08_0066__en-us_topic_0093946912_parmname1637259726101414"><b>1970-01-01 00:00:00</b></span>) represented by an unsigned integer when the function is called without arguments.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_rc37361bb070c46098ee969d1056c7d6b"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_a10b2aa75d271412fb1c5de3ef97c622f">unix_timestamp(string date)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a399286a1b9af40779bca8ae29668dc2f">BIGINT</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_aa0d0c0e52dc94d118d5cf71eb3da9cc3">Return the number of seconds between a specified date and <span class="parmname" id="dli_08_0066__en-us_topic_0093946912_pea0c274818244ab59733f7ea89dc69b1"><b>1970-01-01 00:00:00</b></span>.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_rc43a35090d264c88a57e0587b75df209"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_aa9eed6180815454e84a7512932241518">unix_timestamp(string date, string pattern)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a2e87b5fd8e214916a10321f63ebc557d">BIGINT</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_afdb6ddc77bd04185ac81a114e86c85d2">Convert a time string with a given pattern to a Unix timestamp. Example: unix_timestamp("2009-03-20", "yyyy-MM-dd") = 1237532400.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_r771cfa26f8e34fa8a028ee63c86b15aa"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_a210a906f5e6c4f0badcfdbf61b378246">to_date(string timestamp)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a14394948625241bb95e9806deec7382e">STRING</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_a6f27cdd52f544f4094f973c9db25541c">Return the date part of a time string. Example: to_date("1970-01-01 00:00:00") = "1970-01-01".</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_r02354d3470bb41bd839957d33f0123f5"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_a27f682432d0d4fcfb0b9f3b0ad98c5cc">year(string date)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_ac954302529bb4f7da0c7481ddd6ec524">INT</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_a8bff50cc434a4475bfb9ee58cc80bb03">Return the year part of a date.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_rcc1d8b3776134cc3aea6151a4ebe4f39"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_a8458b70862e34c54895b15134f764fa0">quarter(string date/timestamp/string)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a2b20bbc405c04f0f89be819033b28eb3">INT</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_a0e1f2337d87e4dca8d4188c4744d9c77">Return the quarter of the year for a date, timestamp, or string. Example: quarter('2015-04-01')=2.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_r8509054838e246af8c35abd998c39968"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_aa1d5b57c8bc3410a8399563702399e3f">month(string date)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a14b4f5e7eea84094bfc8b50d03094942">INT</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_a70ea35377a1a4f23bb62e8c904c169a5">Return the month (from 1 to 12) part of a date.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_r13c44d42cc6741bb9135e90f1c28f4c9"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_afd6704524c1d46d5911bc8b4504fd1e0">day(string date) dayofmonth(string date)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a7f8621c3219b42529a67afef8734ca50">INT</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_aa9dc9bda082345fa8d4ef02752742421">Return the day part of a date.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_rd84f7c30fe0c445fba0715a5a7aa0ee5"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_aceb04b4f8b184dd1992bb0f0039c0f6a">hour(string date)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a9895a35a31b4497e8f42220de5699897">INT</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_ade44875771284b6499bbe5e944499231">Return the hour (from 0 to 23) part of a date.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_rfcab8ebba1e24f18ba19c6fde9c6173a"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_af71e952e0db84ca08d36ec29e26825d5">minute(string date)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_ae51c17437a0849eaa5ffd83977e57496">INT</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_af0cc70ef75394f77af8add1926b5b432">Return the minute (from 0 to 59) part of a date.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_r0378607a16bf423d981b0c02acf1c992"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_a1c4bf6ee6a114f5b9dcca2011fc2147c">second(string date)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a5ec965fa707744eb8e282a552c54ce0f">INT</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_a3d596561be704f5d976e624092dd5c31">Return the second (from 0 to 59) part of a date.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_rc04720733c5a4d27a1166a3e0055b6d9"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_a3756604f910f409889f525cc1bea77c8">weekofyear(string date)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a3d8f481feadf4b9ca11a3d9993ef02e1">INT</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_a519b7ee8f95a4bd4b4066cc02c23b848">Return the week number (from 0 to 53) of a date.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_rde82065429324d36923baae214cf9107"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_a4a10ad50e33d4287a276e8904f202557">datediff(string enddate, string startdate)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a7cdc847901c14491834cb3f16e7af573">INT</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_a9b8f42311a5b4dd89f03e74888bd0893">Return the number of days from <strong id="dli_08_0066__en-us_topic_0093946912_b842352706101752">startdate</strong> to <strong id="dli_08_0066__en-us_topic_0093946912_b842352706101750">enddate</strong>.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_rc0fc929a3f9346ef90ab0a63ea823c14"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_aa08552c102b74c03b4b726cdf735865d">date_add(string startdate, int days)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_aed2da6b794fc4ffd94ee573f283a00eb">STRING</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_afeff16082dcc4a8fa0f9a0af2f199a25">Add a number of days to a date.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_r402dec62d2ab424ab19a8ff3c179316e"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_ae4c54c78f1be4f9d807fa0dd23313ada">date_sub(string startdate, int days)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_aa26cf72fbd2f4f5b82b7809cea98adf4">STRING</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_a0ee34b2eff2e4e95a9e5dbfa9e737a7e">Subtract a number of days from a date.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_rcc9ae6976503491d9b26b4616b89ba4f"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_a736ada8748dd4031bea1119fb23d8064">from_utc_timestamp(string timestamp, string timezone)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a3c070617d47a4352ba8b40f57797a0c0">TIMESTAMP</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_a95dbd0426e3c44a1b4e99f1ef0215b90">Convert a UTC timestamp to a timestamp in a given time zone. For example, from_utc_timestamp('1970-01-01 08:00:00','PST') returns 1970-01-01 00:00:00.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_ra98343ddfa8141d089e80cecc6b71c7a"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_aaedc3098b86140e8a8eb8c0eecb691d6">to_utc_timestamp(string timestamp, string timezone)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a3ce66b86d7774c54b5d77fa8466a7770">TIMESTAMP</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_a8e77ec800b0d4da0823005ead145192c">Convert a timestamp in a given time zone to a UTC timestamp. For example, to_utc_timestamp('1970-01-01 00:00:00','PST') returns 1970-01-01 08:00:00.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_r963d6d511d444376b80490a75f6c1b57"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_afa59bb874c244574a30ca53de11a63f2">current_date()</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a7e7ce2f647c24feba2b6629052cedc9c">DATE</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_ab669de3fa3df4fb4aab7ea6693975c4e">Return the current date, for example, 2016-07-04.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_re8df0fc1f0ce4a588f3384b80d78b6d4"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_a99f93209d7aa474190e63530bf8bdbdf">current_timestamp()</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a94326b7d07134d81bcee314519760e97">TIMESTAMP</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_a8578a45068384755a95141de8f4e736b">Return the current time, for example, 2016-07-04 11:18:11.685.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_r2637f9edf70a44d28b848c369180d3c0"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_afb83d7c7b9334cf2b11b865d58efa499">add_months(string start_date, int num_months)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a2f1bd2071672406ab589aba4133eebb4">STRING</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_a1642aa5d8e864b3d915cef0d6c8597e4">Return the date that is <strong id="dli_08_0066__en-us_topic_0093946912_b84235270610193">num_months</strong> after <strong id="dli_08_0066__en-us_topic_0093946912_b84235270610196">start_date</strong>.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_r5042a1b5e71e493ea984ab3ac6c9064b"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_a3ce3e6a7394b45fa866a00bed6d1a5c3">last_day(string date)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a7de571e88c7b4a7c8d022b0d6a3992bc">STRING</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_ac6e9c9c17336448fa5bd5b57dee081f8">Return the last day of the month to which a date belongs. The returned date is in the format of yyyy-MM-dd, for example, 2015-08-31.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_r9471701f77bb4fd3beb44f07e9905453"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_a5fcc50d61d4d47e9bb8146be32d426e1">next_day(string start_date, string day_of_week)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_ae792135267f6422abbbdd193b5a60771">STRING</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_a291c1f3c5eb0418a8b7d1819f596beb6">Return the first date that is later than <strong id="dli_08_0066__en-us_topic_0093946912_b842352706103944">start_date</strong> and nearest to <strong id="dli_08_0066__en-us_topic_0093946912_b842352706103948">day_of_week</strong>. The returned date in the format of yyyy-MM-dd. <strong id="dli_08_0066__en-us_topic_0093946912_b842352706103953">day_of_week</strong> specifies a day of a week. For example, the value of <strong id="dli_08_0066__en-us_topic_0093946912_b842352706103959">day_of_week</strong> can be Monday or FRIDAY.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_r4a11d2650d5a4bb7b87da49bc1112a80"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_a0ff70bef59814c23a9da55d89b8c4110">trunc(string date, string format)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a1e9c536942da45e696ea8ec5147b9b90">STRING</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_abbb6b723921a4969bc13a7a5d9793923">Reset the date in a specified format. Supported formats are MONTH/MON/MM and YEAR/YYYY/YY. Example: trunc('2015-03-17', 'MM') = 2015-03-01.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_rbaa4907804224f23a5b7afebf19a1edd"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_a9c5ce16f36c349cb884c0bf8b787a9ae">months_between(string date1, string date2)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_a3368945249b445e7b45cd4b2c1c3168f">DOUBLE</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_a836520c819ec48a7b294bc784910c6b0">Return number of months between dates <strong id="dli_08_0066__en-us_topic_0093946912_b84235270611019">date1</strong> and <strong id="dli_08_0066__en-us_topic_0093946912_b84235270611017">date2</strong>.</p>
</td>
</tr>
<tr id="dli_08_0066__en-us_topic_0093946912_r7313787b90a042569d964a2f57714c51"><td class="cellrowborder" valign="top" width="26.57%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0066__en-us_topic_0093946912_ad5d9810e76c3411fb3b7c6f8b191962b">date_format(date/timestamp/string ts, string fmt)</p>
</td>
<td class="cellrowborder" valign="top" width="13.81%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0066__en-us_topic_0093946912_af8f60877baca4d0db4c4058d249f7b33">STRING</p>
</td>
<td class="cellrowborder" valign="top" width="59.62%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0066__en-us_topic_0093946912_a050365ba3cd24d5dafe8ab2ea618b7a3">Return the formatted value of <strong id="dli_08_0066__en-us_topic_0093946912_b84235270611036">date/timestamp/string</strong>. The Java SimpleDateFormat format is supported. Example: date_format('2015-04-08', 'y') = '2015'.</p>
<p id="dli_08_0066__p61551135134610">In the format, <strong id="dli_08_0066__b19947703418">y</strong> indicates the year. <strong id="dli_08_0066__b5778821445">Y</strong> indicates the year when the current week is located. A week starts from Sunday and ends on Saturday. If a week crosses years, this week is counted as the next year.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_08_0064.html">Built-in Functions</a></div>
</div>
</div>