Convert Date to number format

  • How can I convert a date to the format yyyymmdd, so that from SELECT getdate () it would appear as 20070424 ?

    Thanks...Nali

  • select convert(char(8), getdate(), 112)

  • Hi,

    assume you have a table with four columns (v_start, v_end, t_start, t_end) which are date (dd-mon-yy). how to convert these date to number?

    thanks in advance.

  • Hi All

    I too have a problem with date values comparision... the below is the code

     CONVERT(VARCHAR(30),TRANS_DATE,101)>(@REPORTDATE)

    where @REPORTDATE is declared as DATETIME

    this condition is working in some of the data bases and its not working in some other databases.....

    Are there any settings to be performed in order to do this...?????.

     


    Thanks ,

    Shekhar

  • - advised is to use the (small of needed) datetime format because of datatype and engine-handling.

    - So in stead of querying CONVERT(VARCHAR(30),TRANS_DATE,101)>(@REPORTDATE) just use

        TRANS_DATE> convert(datetime,@REPORTDATE, 101)

    The reason for this is that you always should convert your variables to the datatype of the column in the table you are using. If an index on that column exists, the engine will use the index whereas it will not use the index - at least less optimal - when you convert to column to something else.

     

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply