Home Sql Sqldate Mysql Time Function

Related Tutorials


 
 

Share on Google+Share on Google+

Mysql Time Function

Advertisement
Mysql Time Function is used to find the current time in hour, minute and second etc.

Mysql Time Function

     

Mysql Time Function is used to find the current time in hour, minute and  second etc.

Understand with Example

The Tutorial illustrate an example from 'Mysql Time Function'. To understand and grasp this example we show you the list of queries that return you the different current date, current time, From Unix Time in hour, minute and second. 

Query to select Current Time  use "CURRENT_TIME()" function:

 

 

The Query below is used to return the current time of a table in database.

 mysql> SELECT CURRENT_TIME();
+----------------+
| CURRENT_TIME() |
+----------------+
| 16:26:19 |
+----------------+
1 row in set (0.00 sec)

Query to Converts a Unix timestamp into a date use "FROM_UNIXTIME(1064431682)":

mysql> SELECT FROM_UNIXTIME(1064431682);
+---------------------------+
| FROM_UNIXTIME(1064431682) |
+---------------------------+
| 2003-09-25 00:58:02 |
+---------------------------+
1 row in set (0.00 sec)

Query to converts the Time into Hour:

The Query to returns a numeric between (0-23) for the hour of the specified time using "HOUR(time)"

mysql> SELECT HOUR('02:02:14');
+------------------+
| HOUR('02:02:14') |
+------------------+
| 2 |
+------------------+
1 row in set (0.00 sec)

Query to converts the Time into Minute:

The Query is useful to returns a numeric between  (0-59) for the minute of the specified time using "MINUTE(time)"

mysql> SELECT MINUTE('02:02:14');
+--------------------+
| MINUTE('02:02:14') |
+--------------------+
| 2 |
+--------------------+
1 row in set (0.00 sec)

Query to converts the seconds to a time using SEC_TO_TIME(seconds):

The Query will help you to return the time by converting the seconds using SEC_TO_TIME ( ) query.

mysql> SELECT SEC_TO_TIME(12345);
+--------------------+
| SEC_TO_TIME(12345) |
+--------------------+
| 03:25:45 |
+--------------------+
1 row in set (0.00 sec)
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 20, 2009

Related Tutorials

Discuss: Mysql Time Function  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com