none
Convert Date to time

    Question

  • Dear All,

    MAy i know how to convert the right varchar(8) ? 

    Example - 20120106 043919  convert to 04:39:19

    SELECT CONVERT(right,VARCHAR(8),STUFF(STUFF(EP_SCAN_DATE,12,0,':'),15,0,':'),112) AS SCANDATE from AcmkIMS.dbo.EP_SCAN_HIST

    Tuesday, July 16, 2013 5:22 AM

Answers

  • Not sure what you are trying; but if you want to convert a time string to time and you are using  SQL Server version 2008 or later then try the below:

    SELECT CAST(STUFF(STUFF(EP_SCAN_DATE,12,0,':'),15,0,':') AS TIME(0)) AS SCANDATE from AcmkIMS.dbo.EP_SCAN_HIST


    Krishnakumar S

    • Marked as answer by Caulson Tuesday, July 16, 2013 7:10 AM
    Tuesday, July 16, 2013 5:34 AM

All replies

  • Not sure what you are trying; but if you want to convert a time string to time and you are using  SQL Server version 2008 or later then try the below:

    SELECT CAST(STUFF(STUFF(EP_SCAN_DATE,12,0,':'),15,0,':') AS TIME(0)) AS SCANDATE from AcmkIMS.dbo.EP_SCAN_HIST


    Krishnakumar S

    • Marked as answer by Caulson Tuesday, July 16, 2013 7:10 AM
    Tuesday, July 16, 2013 5:34 AM
  • DECLARE @ScanDate VARCHAR(8) = '04:39:19'
    
    SELECT CONVERT(TIME(0), @ScanDate, 112)


    http://sqldevelop.wordpress.com/

    Tuesday, July 16, 2013 5:54 AM