Sql Server string to date conversion

后端 未结 14 714
执笔经年
执笔经年 2020-11-22 09:18

I want to convert a string like this:

\'10/15/2008 10:06:32 PM\'

into the equivalent DATETIME value in Sql Server.

In Oracle, I wou

14条回答
  •  既然无缘
    2020-11-22 09:59

    Took me a minute to figure this out so here it is in case it might help someone:

    In SQL Server 2012 and better you can use this function:

    SELECT DATEFROMPARTS(2013, 8, 19);
    

    Here's how I ended up extracting the parts of the date to put into this function:

    select
    DATEFROMPARTS(right(cms.projectedInstallDate,4),left(cms.ProjectedInstallDate,2),right( left(cms.ProjectedInstallDate,5),2)) as 'dateFromParts'
    from MyTable
    

提交回复
热议问题