Fiaola wrote:
Quote:
I'm trying to write an SQL Query in SQL Server 2008 to update a date
field in my table. The field is a DATETIME field type. When a record
is inserted and it is over midnight (lets' say between MIDNIGHT 00:00
AM AND 03:00 AM, i want to store the previous Date.
Any help would be appreciated. Thanks in ADVANCE |
If you are only interesting in storing the date portion, then you could
use this:
CREATE TABLE #t (my_datetime_column datetime)
INSERT INTO #t VALUES ('20101030 11:00')
INSERT INTO #t VALUES ('20101027 02:30')
INSERT INTO #t VALUES ('20101021 05:00')
INSERT INTO #t VALUES ('20101015 23:59')
SELECT my_datetime_column
, DATEADD(day, DATEDIFF(day, 0, DATEADD(hour, -3,
my_datetime_column)), 0)
FROM #t
DROP TABLE #t
--
Gert-Jan