Knowledge Walls
John Peter
Pune, Maharashtra, India
How to get total milliseconds, seconds, minutes and hour by Date in Mysql
10468 Views
Getting seconds in Mysql 
unix_timestamp() function return number of seconds in given date.

Example
select unix_timestamp(now());

Output
1398734374

1398734374 is the total number of seconds from now() date.
Getting present total milliseconds by Date in Mysql 
unix_timestamp(now()) returns total number of seconds. So multiply this with 1000 to get total milliseconds like below.

Example
select unix_timestamp(now()) * 1000;

Output
1398734374000
To get total minutes by Date in mysql 
unix_timestamp() divide by total seconds per minute(60) to get total minutes till now in mysql.

Example
select unix_timestamp(now()) / 60;

Output
23312240
Total hour by date in Mysql 
unix_timestamp() divide by total seconds per minute(60) and total minutes per hour(60) to get total hours till now in mysql.

Example
select unix_timestamp(now()) / 60 / 60;

Output
388537
Previous Topics
Previous lessons of current book.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details