How do I strip the date off of a datetime string in SQL SSIS?

前端 未结 5 662
情话喂你
情话喂你 2020-12-20 23:49

I\'m working on a data warehouse project and would like to know how to (preferably in a Derived Column component in a Data flow) strip the date piece off of a SQL datetime r

5条回答
  •  情书的邮戳
    2020-12-21 00:08

    Ran into this with writing a report for a scheduling app, needed the time that was stored as part of a datetime data type. I formated the datetime as 0 which gives you this mon dd yyyy hh:miAM (or PM), and just did a substring of that which returned the time only in an AM/PM format.

    Example below.

    DECLARE @S DATETIME = GETDATE()
    
    SELECT SUBSTRING(CONVERT(NVARCHAR(30), @S , 0) , 13 , 10) AS ApptTime
        , CONVERT(NVARCHAR(30), @S , 0) AS ApptDate
    

提交回复
热议问题