blob: 9995b3750f9fe0513df208ff94375aca995e6196 [file] [log] [blame] [view]
---
{
"title": "UNIX_TIMESTAMP",
"language": "en"
}
---
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
## unix_timestamp
### Description
#### Syntax
`INT UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])`
Converting a Date or Datetime type to a UNIX timestamp.
If there are no parameters, the current time is converted into a timestamp.
The parameter needs to be Date or Datetime type.
Any date before 1970-01-01 00:00:00 or after 2038-01-19 03:14:07 will return 0.
See `date_format` function to get Format explanation.
This function is affected by time zone.
### example
```
mysql> select unix_timestamp();
+------------------+
| unix_timestamp() |
+------------------+
| 1558589570 |
+------------------+
mysql> select unix_timestamp('2007-11-30 10:30:19');
+---------------------------------------+
| unix_timestamp('2007-11-30 10:30:19') |
+---------------------------------------+
| 1196389819 |
+---------------------------------------+
mysql> select unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s');
+---------------------------------------+
| unix_timestamp('2007-11-30 10:30-19') |
+---------------------------------------+
| 1196389819 |
+---------------------------------------+
mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s');
+---------------------------------------+
| unix_timestamp('2007-11-30 10:30%3A19') |
+---------------------------------------+
| 1196389819 |
+---------------------------------------+
mysql> select unix_timestamp('1969-01-01 00:00:00');
+---------------------------------------+
| unix_timestamp('1969-01-01 00:00:00') |
+---------------------------------------+
| 0 |
+---------------------------------------+
```
### keywords
UNIX_TIMESTAMP,UNIX,TIMESTAMP