Format _MDDyy to a standard date


  
  
 


select *, Cast('20'+ Right(policyexpire,2)+ Left(Right('0'+policyexpire,6) ,4) as date)  

,datefromparts(2000+ cast(Right(policyexpire,2)as int),Cast(Left(Right('0'+policyexpire,6) ,2) as int) , cast(Left(Right(policyexpire,4),2) as int) )
,datefromparts(2000+  Right(policyexpire,2) , Left(Right('0'+policyexpire,6) ,2)  , Left(Right(policyexpire,4),2)   )

 ,CAST(STUFF(STUFF(Right('0'+policyexpire,6),3,0,'/'),6,0,'/') as DATE)
 ,CONVERT(DATE,STUFF(STUFF(Right('0'+policyexpire,6),3,0,'/'),6,0,'/') )

,CONVERT(DATE,Right( policyexpire ,2)+ Left(Right('0'+policyexpire,6) ,4) ,12)
,Cast(Right( policyexpire ,2)+ Left(Right('0'+policyexpire,6) ,4) as DATE)
 
,TRY_CONVERT(DATE,Right( policyexpire ,2)+ Left(Right('0'+policyexpire,6) ,4) ,12)
--,TRY_CAST(Right( policyexpire ,2)+ Left(Right('0'+policyexpire,6) ,4) as DATE) 
,TRY_PARSE(Right( policyexpire ,2)+ Left(Right('0'+policyexpire,6) ,4) as DATE)
from atable


 
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s