change date format

Hi,
I have the variable "$date_update" in that form:

2011-12-31T13:00:09Z

and I would like to change it to

31/12/2011 13:00:09

(Date and Time separated by a blank).

Does anyone has a simple solution for that? (using Korn Shell)

Cheers
Jurgen

Ugly as sin, but effective

echo "2011-12-31T13:00:09Z"|sed 's/\([0-9]\{4\}\)-\([0-9]\{2\}\)-\([0-9]\{2\}\)T\([0-9]\{2\}\):\([0-9]\{2\}\):\([0-9]\{2\}\)Z/\3\/\2\/\1 \4:\5:\6/'
1 Like

A slight variation:

echo "2011-12-31T13:00:09Z"|sed -e "s_\([0-9]\{4\}\)-\([0-9]\{2\}\)-\([0-9]\{2\}\).\([0-9:]\{1,\}\).*_\3/\2/\1 \4_g"
31/12/2011 13:00:09
1 Like

A boring way:

OLD="2011-12-31T13:00:09Z"
HHMMSS=`echo "${OLD}"|cut -c12-19`
YYYY=`echo "${OLD}"|cut -c1-4`
MM=`echo "${OLD}"|cut -c6-7`
DD=`echo "${OLD}"|cut -c9-10`
NEW="${DD}/${MM}/${YYYY} ${HHMMSS}"
echo "${NEW}"


31/12/2011 13:00:09

both codes are working,

thanks for the help

Jurgen