Convert Datetimeoffset to DateTime in SQL Server

Datetimeoffset to DateTime Convert issue in SQL Server 2016 Database. You are facing issue in one conversion, which is working fine in 2008 DB but not in 2016 DB. Select Convert(DateTime,created_ts,20) From Table Where, created_ts Type is DateTimeOffset. Its throwing error in 2016, as “The style 20 is not supported for conversions from datetimeoffset to datetime.” Please see … Read more

SQL: How to get previous and current month records?

SQL Server – Database Design. How to return the current month first date and the previous month first date between values, but its gives us the different values. You can do like this: f.StartDateKey >= DATEADD(mm,DATEDIFF(mm,0,GETDATE())-1,0) and f.StartDateKey < DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0) Another way is this (if on SQL 2012 and above) f.StartDateKey >= DATEADD(dd,1,EOMONTH(GETDATE(),-2)) and f.StartDateKey … Read more