UFN_DATETIMEOFFSET_GETLATESTTIME
Returns the latest 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_GETLATESTTIME]
(
@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.
--Then we must add 1 day and subtract 3 ms in order to get the latest possible time for a given date.
--However, this also truncates the timezone offset, so we need to add that back.
return todatetimeoffset(dateadd(ms, -3, dateadd(d, 1, cast(cast(@DATE as date) as datetimeoffset))), datepart(tz, @DATE));
end