default date format

  • 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

  • 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

  • Yes, conversion to int would be so simple...

    But it depends on what degree of accuracy you need.

    Frank

    http://www.insidesql.de

    http://www.familienzirkus.de

    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]

  • 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

  • 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