Skip to main content

This piece of code helped me when trying to manage and add times and dates together, T-SQL

declare @datet datetime;
set @datet = GETDATE();

select
    @datet,
    cast(@datet as date),
    cast(@datet as time);

select
    cast(cast(@datet as date) as datetime),
    cast(cast(@datet as time) as datetime),
    cast(cast(@datet as date) as datetime) + cast(cast(@datet as time) as datetime);

Comments

Popular posts from this blog