home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 17,994 of 19,505   
   Gert-Jan Strik to Fiaola   
   Re: check if a DateTime value is over mi   
   30 Oct 10 20:28:18   
   
   2d566d39   
   From: sorrytoomuchspamalready@xs4all.nl   
      
   Fiaola wrote:   
   >   
   > 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   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca