Home > Database > Mysql Tutorial > body text

How to get total seconds from MySQL DATETIME instance?

王林
Release: 2023-08-27 14:29:15
forward
1327 people have browsed it

如何从 MySQL DATETIME 实例获取总秒数?

MySQL DateTime instance can be converted to seconds via UNIX_TIMESTAMP() function as follows -

mysql> Select UNIX_TIMESTAMP('2017-05-15 04:05:30') AS 'NUMBER OF SECONDS';

+-------------------+
| NUMBER OF SECONDS |
+-------------------+
|        1494801330 |
+-------------------+
1 row in set (0.00 sec)
Copy after login

The above query will convert the given datetime instance to total seconds .

mysql> Select UNIX_TIMESTAMP(NOW()) AS 'NUMBER OF SECONDS';

+-------------------+
| NUMBER OF SECONDS |
+-------------------+
|        1509248856 |
+-------------------+
1 row in set (0.00 sec)
Copy after login

The above query will convert the current DateTime instance into total seconds.

mysql> Select UNIX_TIMESTAMP(Dateofreg) AS 'NUMBER OF SECONDS' from
       testing where StudentName = 'Gaurav';

+-------------------+
| NUMBER OF SECONDS |
+-------------------+
|        1509247113 |
+-------------------+
1 row in set (0.00 sec)
Copy after login

The above query will convert a DateTime instance which is a stored value in table "testing" where column StudentName has the value "Gaurav".

The above is the detailed content of How to get total seconds from MySQL DATETIME instance?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!