programmer138200 programmer138200 - 8 months ago 23
SQL Question

How to split one section of string via Tsql?

I try to split this string

3/9/1395 12:00:00 AM
and get this string
.I search but sql has no method for this work. How to do this?


You can convert your variable to a Date and get Year, Month and Day

DATEPART(YEAR,Cast('3/9/1395 12:00:00 AM' as date)) 

DATEPART(MONTH,Cast('3/9/1395 12:00:00 AM' as date)) 

DATEPART(DAY,Cast('3/9/1395 12:00:00 AM' as date))