Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update a date part
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01059700
Message ID:
01059990
Views:
11
>You can use a combination of DATEADD() and DATEDIFF() functions to perform what you are trying to do. Basically the code below calls the DATEDIFF function to return the time portion as the number of milliseconds, then calls the DATEADD function to add the number of millisec's to the date. This assumes that you always want to add the time portion from @settime to the @newdate variable and the time portion of @newdate is always 00:00:00.
>
>
>DECLARE @settime DATETIME,
>        @newdate DATETIME,
>        @result  DATETIME
>
>SELECT @settime = '1/1/1900 9:10:48 AM',
>       @newdate = '7/13/2005'
>
>
>SELECT @result = DATEADD(ms,DATEDIFF(ms,'01/01/1900',@settime),@newdate)
>PRINT @result
>
You'll get incorrect result for any other date. Try, for example,
SELECT @settime = '12/10/1999 9:10:48 AM'
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform