- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the total number of seconds from a MySQL DATETIME instance?
The MySQL DateTime instance can be converted into seconds with the help of UNIX_TIMESTAMP() function in the following way −
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)
Above query will convert the given datetime instance into total number of seconds.
mysql> Select UNIX_TIMESTAMP(NOW()) AS 'NUMBER OF SECONDS'; +-------------------+ | NUMBER OF SECONDS | +-------------------+ | 1509248856 | +-------------------+ 1 row in set (0.00 sec)
Above query will convert the current DateTime instance into a total number of 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)
Above query will convert the DateTime instance which is a stored value in a table ‘testing’ where column StudentName is having value ‘Gaurav’.
- Related Articles
- Remove seconds from MySQL Datetime?
- MySQL query to get only the minutes from datetime?
- Get only the date from datetime in MySQL?
- Python Pandas - Get the Total seconds in the duration from the Timedelta object
- How to convert DateTime to a number in MySQL?
- How can we get the total number of rows affected by MySQL query?
- MySQL DateTime Now()+5 days/hours/minutes/seconds?
- Can we get total number of rows in a MySQL database?
- What is the equivalent of MySQL TIME_TO_SEC() method in PHP to convert datetime to seconds?
- How to get the number of seconds between two Dates in JavaScript?
- Get total number of rows while using LIMIT in MySQL?
- How to get the total number of checkboxes in a page using Selenium?
- How to subtract 3 hours from a datetime in MySQL?
- How to get the total number of radio buttons on a page using Selenium?
- How to select only MySQL date from datetime column?

Advertisements