sql-server

convert datetime to bigint


is there a function to convert datetime to bigint in sql? E.g. I have a date "2010-11-02 00:00:00" and i would like to get result as number "20101102000000"

Or do I need to write some custom function which will remove -,space,: from datetime?


Solution

  • you can try this code here..

    update Table_1 set xnew=REPLACE(REPLACE(REPLACE (CONVERT(VARCHAR,x,20) , '-' , '' ),':',''),' ','')
    

    but this is duplicate question I answered it here too : Sql datatype conversion