I have an sql DateTime (ms sql server) and want to extract the same date without the seconds: e.g. 2011-11-22 12:14:58.000 to become: 2011-11
DateTime
2011-11-22 12:14:58.000
2011-11
If there is no milliseconds, than
DECLARE @dt datetime2 = '2011-11-22 12:14:58.000'; DECLARE @goalDt datetime2 = DATEADD(second,-DATEPART(second,@dt), @dt);
To remove a milliseconds part, add
SET @goalDt = DATEADD(millisecond,-DATEPART(millisecond,@goalDt ), goalDt dt);