Here is his basic code. A bit too complicated for my taste, but it gets the job done:
Code: Select all
#! /bin/bash
from="DonaldDuck"
var1="06/11/15 13:21" # November 6th 2015 at 1:21 pm
var2=$(echo $var1 | sed 's/\//-/g' | sed 's/ /-/g' | awk '{print substr($0,7,2) substr($0,3,4) substr($0,1,2) substr($0,9,6)}')
var3="20"$var2"-"
echo $var3$from # 2015-11-06-13:21-DonaldDuck
First attempt. November turns to June. Good idea, but wrong.
Code: Select all
date -d "$var1" +%Y-%m-%d-%R-"$from" # 2015-06-11-13:21-DonaldDuck
Code: Select all
var1=${var1//\//-} # 06-11-15 13:21
date -d "$var1" +%Y-%m-%d-%R-"$from" # 2006-11-15-13:21-DonaldDuck
Code: Select all
busybox date -D '%d/%m/%y %H:%M' -d "$var1" +%Y-%m-%d-%R-"$from" # 2015-11-06-13:21-DonaldDuck
Edit: On my system busybox uses 10 times less CPU time than date, despite having to translate the -d string. date knows much more common formats than busybox and therefore allows shorter (and more portable) code, but still busybox is hard to beat in terms of flexibility.
.