programmer138200 programmer138200 - 1 year ago 86
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?

Answer Source

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))

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download