Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

remove last character from date and format to date

$
0
0

Hi,

I have a field (called '
pehPErcontrol') that
contains a date value, plus one character. But the value is formatted like
this:

201301042

I need to remove the last character (last '2' in
the above example) but I also need to format the left over value (20130104) to a
date value:

01/04/2013

How can I do this?

I've tried but can't get it to work:

cast(left('pehPErcontrol',8) as datetime), 

--ERROR Conversion failed when converting datetime from character string.

(datetime,'pehPErcontrol',101)


qeqw


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>