UFN_DATETIMEOFFSET_GETEARLIESTTIME

Returns the earliest time for the given datetimeoffset.

Return

Return Type
datetimeoffset

Parameters

Parameter Parameter Type Mode Description
@DATE datetimeoffset IN

Definition

Copy


CREATE function dbo.[UFN_DATETIMEOFFSET_GETEARLIESTTIME]
(
  @DATE datetimeoffset
)
returns datetimeoffset
with execute as caller
as
begin
  --Casting to a "date" is the most efficient way to truncate the time and get the earliest time for a given date.

  --However, this also truncates the timezone offset, so we need to add that back.

  return todatetimeoffset(cast(cast(@DATE as date) as datetimeoffset), datepart(tz, @DATE));
end