Share via


Date and Time Canonical Functions (Entity SQL)

Entity SQL includes date and time canonical functions.

Remarks

The following table shows the date and time Entity SQL canonical functions. datetime is a System.Datetime value.

Function Description

CurrentDateTime()

Returns a System.Datetime value as the current date and time of the server in the server's time zone.

Return Value

A DateTime.

CurrentDateTimeOffset()

Returns the current date, time and offset as an DateTimeOffset.

Return Value

A DateTimeOffset.

CurrentUtcDateTime()

Returns a System.Datetime value as the current date and time of the server in the UTS time zone.

Return Value

A DateTime.

Day( expression )

Returns the day portion of expression as an Int32 between 1 and 31.

Arguments

A DateTime and DateTimeOffset.

Return Value

An Int32.

Example

-- The following example returns 12.

Day(cast('03/12/1998' as DateTime))

GetTotalOffsetMinutes ( datetimeoffset )

NoteNote
This function is supported in SQL Server 2008 only.

Returns the number of minutes that the datetimeoffset is offset from GMT. This is generally between +780 and -780 (+ or - 13 hrs).

Arguments

A DateTimeOffset.

Return Value

An Int32.

Hour ( expression )

Returns the hour portion of expression as an Int32 between 0 and 23.

Arguments

A DateTime, Time and DateTimeOffset.

Example

-- The following example returns 22.

Hour(cast('22:35:5' as DateTime))

Millisecond( expression )

Returns the milliseconds portion of expression as an Int32 between 0 and 999.

Arguments

A DateTime, Time and DateTimeOffset.

Return Value

An Int32.

Minute( expression )

Returns the minute portion of expression as an Int32 between 0 and 59.

Arguments

A DateTime, Time and DateTimeOffset.

Return Value

An Int32.

Example

-- The following example returns 35

Minute(cast('22:35:5' as DateTime))

Month (expression)

Returns the month portion of expression as an Int32 between 1 and 12.

Arguments

A DateTime and DateTimeOffset.

Return Value

An Int32.

Example

-- The following example returns 3.

Month(cast('03/12/1998' as DateTime))

Second( expression )

Returns the seconds portion of expression as an Int32 between 0 and 59.

Arguments

A DateTime, Time and DateTimeOffset.

Return Value

An Int32.

Example

-- The following example returns 5

Second(cast('22:35:5' as DateTime))

Year( expression )

Returns the year portion of expression as an Int32 YYYY.

Arguments

A DateTime and DateTimeOffset.

Return Value

An Int32.

Example

-- The following example returns 1998.

Year(cast('03/12/1998' as DateTime))

These functions will return Null if given Null input.

Equivalent functionality is available in the Microsoft SQL Client Managed Provider. For more information, see .NET Framework Data Provider for SQL Server (SqlClient) for the Entity Framework Functions.

See Also

Concepts

Canonical Functions (Entity SQL)