SQL SECOND() Function


The SQL SECOND() is a function, and return or extract the second portion of a given input time value.

The SQL SECOND() function returns a integer number specifying a whole number between 0 and 59, inclusive, representing the second of the SECONDs.

The SQL SECOND() function is supports only datetime or timestamp based table columns or fields.

It can be used in SELECT statement as well in where clause.


Search Keys

    The remote server returned an error: (404) Not Found.

Related Links

    The remote server returned an error: (404) Not Found.

SQL SECOND() Syntax

The below syntax is used to get second of the SECOND value (a integer number between 0 to 59, inclusive) from a given input datetime value.

For SQL SERVER / MY SQL / MS ACCESS


SELECT SECOND('valid_datetime_value' or 'valid_timestamp_value');


SQL SECOND() Example - Using Expression Or Formula

The following SQL SELECT statement will extract the second of the SECOND value from a given input datetime value. We use now() function to get the input date value.


SELECT 
NOW() AS 'Current Date and Time', 
SECOND(NOW()) AS 'Second Value';

The result of above query is:

Current Date and Time Second Value
24-08-2012 19:37:30 30

Sample Database Table - BookOrder

BookID BookName OrderDate Qty DeliveryDate
1 The Database Language SQL 16-06-2009 13:16:48 9 20-07-2009 23:21:37
2 Pro Oracle SQL 12-07-2007 01:24:50 7 26-07-2007 04:09:30
3 A Visual Introduction To Sql 11-02-2004 02:02:31 1 17-02-2004 14:17:10
4 Access 2010 Pure Sql 20-05-2010 05:50:19 2 28-05-2010 08:35:55
5 Structured Query Language for all RDBMS 15-04-2001 03:18:49 4 24-05-2001 08:07:38
6 Pro Full-text Search In SQL Server 18-02-2002 03:41:48 5 27-03-2002 07:11:32
7 Oracle All-in-One For Dummies 22-05-2007 11:35:32 1 27-05-2007 23:20:21
8 Introduction to SQL and PL/SQL 20-01-2009 17:41:16 8 23-02-2009 21:07:14
9 SQL Functions Reference 23-05-2008 03:17:59 18 26-05-2008 12:07:48
10 SQL Server 2008 Transact-Sql 11-10-1997 09:27:16 5 22-10-1997 12:17:45
11 Sql Server Concurrency 23-06-2004 11:19:32 1 28-07-2004 02:22:04
12 SQL and Relational Database Design 24-10-1998 14:28:43 5 28-10-1998 16:57:13

SQL SECOND() Example - With Table Column

The following SQL SELECT statement display the column "OrderDate" and "DeliveryDate" from the "BookOrder" table. The SECOND() function will extract the SECOND value(a whole integer number from 1 to 60) from the column "OrderDate" and we will stored that value to a new column called "Order SECOND" and "Delivery SECOND".


SELECT 
OrderDate, SECOND(OrderDate) As 'Order SECOND', 
DeliveryDate, SECOND(DeliveryDate) As 'Delivery SECOND' 
FROM BookOrder;

The result of above query is:

OrderDate Order SECOND DeliveryDate Delivery SECOND
16-06-2009 13:16:48 48 20-07-2009 23:21:37 37
12-07-2007 01:24:50 50 26-07-2007 04:09:30 30
11-02-2004 02:02:31 31 17-02-2004 14:17:10 10
20-05-2010 05:50:19 19 28-05-2010 08:35:55 55
15-04-2001 03:18:49 49 24-05-2001 08:07:38 38
18-02-2002 03:41:48 48 27-03-2002 07:11:32 32
22-05-2007 11:35:32 32 27-05-2007 23:20:21 21
20-01-2009 17:41:16 16 23-02-2009 21:07:14 14
23-05-2008 03:17:59 59 26-05-2008 12:07:48 48
11-10-1997 09:27:16 16 22-10-1997 12:17:45 45
23-06-2004 11:19:32 32 28-07-2004 02:22:04 4
24-10-1998 14:28:43 43 28-10-1998 16:57:13 13

Search Keys

    The remote server returned an error: (404) Not Found.

Related Links

    The remote server returned an error: (404) Not Found.