Convert date arg to sql date

Doing a bcp load to sybase and need to convert datearg which comes in as 20130501 to 2013-05-01 which is the best way to do this

[user@host ~]$ x=20130501
[user@host ~]$ echo "${x:0:4}-${x:4:2}-${x:6}"
2013-05-01
[user@host ~]$
$fulldate=20130430
bdate=`{$fulldate:0:4}-{$fulldate:4:2}-{$fulldate:6}`
echo $bdate

does not seem to work when I try to assign it as var

There should be no dollar before "fulldate".

fulldate=20130430

Dollar should be outside the curly braces.

bdate=`${fulldate:0:4}-${fulldate:4:2}-${fulldate:6}`
1 Like

works fine now