SQLite time

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

SQLite time() function

Description

SQLite TIME() extracts the time part of a time or datetime expression as string format.

The time() function returns the time as HH:MM:SS.

Syntax

  1. time(timestring, modifier, modifier, ...)  

Example-1 :

If you want to get the current time the following SQL can be used.

  1. SELECT time('now'as "Current Time";  
  2. or  
  3. SELECT time() as "Current Time";  

Here is the result.

Current Time
------------
10:37:30

Example-2 :

The following statement will return the time portion from the given date-time value 2014-10-07 15:45:57.005678.

  1. SELECT time('2014-10-07 15:45:57.005678'as "Only time part";  

Here is the result.

Only time part
--------------
15:45:57

Example-3 :

If you want to get the time after 15 minutes from the current time, the following SQL can be used.

  1. SELECT TIME('now'),TIME('now','+15 minutes');  

Here is the result.

TIME('now')  TIME('now','+15 minutes')
-----------  -------------------------
11:22:26     11:37:26

Example-4 :

If you want to get the time after 60 seconds from the current time the following SQL can be used.

  1. SELECT TIME('now'),TIME('now','+60 seconds');  

Here is the result.

TIME('now')  TIME('now','+60 seconds')
-----------  -------------------------
11:24:14     11:25:14