MySQL function equivalent

Hi,

In MySQL, from_unixtime(lonvalue) returns the date format in 'YYYY-MM-DD HH:MM:SS'. Is there any equivalent available in SQL Server, to view the date in man readable format, when the input is an long value in milliseconds.

Eg :

SELECT FROM_UNIXTIME(875996580);

Thanks,
Smitha




Answer this question

MySQL function equivalent

  • Erland Sommarskog

    Take a look at the CONVERT function in Books Online. It has different styles that you can use. Optionally you can format the string using various datepart calls.

    select CONVERT(varchar, CURRENT_TIMESTAMP, 121) -- odbc canonical format

  • Daljinder

    select CONVERT(varchar, '875996580', 121);

    Output :  875996580 


    As I had said earlier, the input is a long value (in milliseconds)




  • HaLaBi

    There is no native function that will understand the Unix format directly. You have to write your own TSQL UDF to do the conversion based on the format.

  • Roberto Kramer

    isnt 'from_unixtime(longvalue)' return a date that is longvalue seconds from 1/1/1970 not milleseconds

    select dateadd(s, 875996580, '1/1/1970')
    yields:
    1997-10-04 20:23:00.000



  • MySQL function equivalent