Hello,
I have date format as shown in red color below
Fri, Sep 12, 2012 08:38:05 PM
Can anyone help me with command to change this format to yyyy-mm-dd and HH:MM:SS
Note: Time should be in 24 hours format
I really appreciate your help!!
Thanks,
Elavarasan
I assume you mean: use date command with another format --
date "+%Y-%m-%d %H:%M:%S"
The date format string starts with the + character, it does not show up in the output.
If you forget it you get an error message
1 Like
Thanks for your helping!!
Your command will give current date and time, but i will have old date and time that need to be convert to another format as shown in my first thread.... hmmmm
pamu
October 20, 2012, 5:42am
4
Check if -d
option is present or not..?
$date -d "Fri, Sep 12, 2012 08:38:05 PM" "+%Y-%m-%d %H:%M:%S"
2012-09-12 20:38:05
Or
date --date="Fri, Sep 12, 2012 08:38:05 PM" "+%Y-%m-%d %H:%M:%S"
Yoda
October 20, 2012, 12:34pm
5
Since there is no -d option present in HP-UX
export INP_DT="Fri, Sep 12, 2012 08:38:05 PM"
export FMT_DT=`echo ${INP_DT} | sed 's/\,/\//g;s/\:/\//g;s/ /\//g;s/\/\//\//g'`
perl '-MPOSIX qw(strftime)' -le'
@dt = split /\//, $ENV{'FMT_DT'};
print strftime( "%Y-%b-%d %I:%M:%S", $dt[6], $dt[5], $dt[4], $dt[2], $dt[1], $dt[3] - 1900 )';