December 5, 2003 at 1:34 pm
quote:
Quick brainteaser for our beginning DBA's: what's the quickest method to strip out the time from a DATETIME field (returning only the date)?
CAST(<datetime value> as int)
* Noel
December 5, 2003 at 3:14 pm
quote:
quote:
Quick brainteaser for our beginning DBA's: what's the quickest method to strip out the time from a DATETIME field (returning only the date)?CAST(<datetime value> as int)
Nope. Strangely enough, that actually rounds based on the time of day; datetimes after noon would be returned as the next day. Conversions to int are inconsistent, unfortunately: money and temporal types round, decimal and approximate numeric truncate.
--Jonathan
--Jonathan
December 5, 2003 at 3:18 pm
Yes, conversion to int would be so simple...
But it depends on what degree of accuracy you need.
Frank
Sorry for editing...
The wine has now begun to show its effect...
I log off now until monday! (Promised Patrick!!!)
I wish a real great weekend to you all!
Edited by - Frank kalis on 12/05/2003 3:21:12 PM
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
December 5, 2003 at 4:46 pm
quote:
quote:
--------------------------------------------------------------------------------
quote:
--------------------------------------------------------------------------------
Quick brainteaser for our beginning DBA's: what's the quickest method to strip out the time from a DATETIME field (returning only the date)?
--------------------------------------------------------------------------------
CAST(<datetime value> as int)
--------------------------------------------------------------------------------
Nope. Strangely enough, that actually rounds based on the time of day; datetimes after noon would be returned as the next day. Conversions to int are inconsistent, unfortunately: money and temporal types round, decimal and approximate numeric truncate.
I have to admit I only tested with "yyyy-mm-dd 00:00:00" values
Good to know!
* Noel
December 6, 2003 at 5:46 am
Instead of CAST(<datetime value> as int) you can use FLOOR(CONVERT(DECIMAL(19,9), <datetime value>)) or CEILING(...).
To change the front-end format you can use SET LANGUAGE ...
123123
123123
Viewing 5 posts - 16 through 19 (of 19 total)
You must be logged in to reply to this topic. Login to reply