How can I convert strings holding some time and date in plain format, e.g. 20:21:14 - 21/01/2020
to a unix timestamp format, e.g.1579638074
in SQL?
Thanks
How can I convert strings holding some time and date in plain format, e.g. 20:21:14 - 21/01/2020
to a unix timestamp format, e.g.1579638074
in SQL?
Thanks
You can use UNIX_TIMESTAMP(); function UNIX_TIMESTAMP(); UNIX_TIMESTAMP(date);
For more information please visit - https://www.w3resource.com/mysql/date-and-time-functions/mysql-unix_timestamp-function.php
SELECT UNIX_TIMESTAMP(STR_TO_DATE('20:21:14 - 21/01/2020','%h:%i:%s - %d/%m/%Y'))n;
SELECT STR_TO_DATE('2014-05-28 11:30:10','%Y-%m-%d %H:%i:%s');
SELECT STR_TO_DATE('20140528 11:30:10','%Y%m%d %H:%i:%s');
SELECT STR_TO_DATE('2014-05-28 113010','%Y-%m-%d %H%i%s') ;
SELECT STR_TO_DATE('20140528 113010','%Y%m%d %H%i%s');
I Think This Will Help You.
Use Unix_TIMESTAMP
UNIX_TIMESTAMP(timestring)
Time format: YYYY-MM-DD HH:MM:SS or YYMMDD or YYYYMMDD
Example:
MariaDB [testl]> create table test(time int(15));
Query OK, 0 rows affected (0.416 sec)
MariaDB [testl]>
MariaDB [testl]> insert into test(time) values(UNIX_TIMESTAMP('2020-01-21 20:21:14'));
Query OK, 1 row affected (0.102 sec)
MariaDB [testl]> select * from test;
+------------+
| time |
+------------+
| 1579618274 |
+------------+
1 row in set (0.039 sec)