Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 » UltraLite - Database Management and Reference » UltraLite SQL Reference » UltraLite SQL functions » SQL functions (A-D)

 

DATEPART function [Date and time]

Returns the value of part of a datetime value.

Syntax
DATEPART( date-part, date-expression )
Parameters
  • date-part   The date part to be returned.

    For a complete listing of allowed date parts, see Date parts.

  • date-expression   The date for which the part is to be returned.

Returns

INT

Remarks

The date must contain the date-part field.

Standards and compatibility
  • SQL/2003   Vendor extension.

Example

The following statement returns the value 5.

SELECT DATEPART( month , '1987/05/02' );

The following example creates a table, TableStatistics, and inserts into it the total number of sales orders per year as stored in the SalesOrders table:

CREATE TABLE TableStatistics ( 
   ID INTEGER NOT NULL DEFAULT AUTOINCREMENT, 
   Year INT, 
   NumberOrders INT );
INSERT INTO TableStatistics ( Year, NumberOrders )
   SELECT DATEPART( Year, OrderDate ), COUNT(*)
   FROM SalesOrders
   GROUP BY DATEPART( Year, OrderDate );