I’ve got a bunch of datetime values where I need to replace the date part with a specific date passed as a parameter (an nvarchar(8) formatted as YYYYMMDD). The time part should stay same as before.
For instance, I’ve got this row of datetime values:
Id | DocDate | CreationDate | PrintDate
1 | 2012-10-01 00:44:20.150 | 2012-10-07 00:44:20.150 | 2012-10-07 00:50:20.150
If I’m passing '20121005', the values should change like this:
Id | DocDate | CreationDate | PrintDate
1 | 2012-10-05 00:44:20.150 | 2012-10-05 00:44:20.150 | 2012-10-05 00:50:20.150
How can I do that?
The pattern of changing just the date portion of a datetime is to first find the difference (in days) that you need to apply, then apply it.