Hello Everybody!
I am looking for help to accomplish following task in T-SQL: I have a timezone, and I need to calculate an UTC datetime which is current date minus one month, but has 0 hours and 0 minutes in a given timezone.
Hello Everybody!
I am looking for help to accomplish following task in T-SQL: I have a timezone, and I need to calculate an UTC datetime which is current date minus one month, but has 0 hours and 0 minutes in a given timezone.
Is this what you need?
Select Cast(Floor(Cast(DateAdd(month, -1, getutcdate()) as float)) as datetime)
SQL Server 2008 and later provides the datetimeoffset type that includes a timezone. You can change the timezone using the SWITCHOFFSET function to change timezone and the DATEADD function to add -1 month to the resulting value. Then you can convert to the DATE type to eliminate the time part.
select cast(DATEADD(month,-1,todatetimeoffset(GETUTCDATE(),'+02:00')) as DATE)