Date conversion

Hi,

I have the string YYYYMMDDHHMMSS like 20090801204150 and I need to convert it using the unix command date in the format:
date "Saturday, 1 August 2009 20:40:59"

All in one single Unix line if this is possible. What's the correct syntax?

Steve Hagi

date -d "20090801204150" "+%A, %d %B %Y %H:%M:%S"

This only works with GNU date (usually comes with Linux)

Hi Jim,

thanks for quick reply. Anyway I receive:

date: settimeofday (timezone): Operation not permitted

I don't need to set date, I need only to convert and get a string formatted from YYYYMMDDHHMMSS input. We use OS X.

Steve Hagi

Sounds like Apple excised that feature from their strange half-GNU UNIX base... Pity. GNU date's usefulness is severely limited by the single format in which it will accept dates anyway though, and this format is not it. On my system I'd be severely tempted to use mysql for date processing just because I have it.

Should work for you.

# DATE=20090801204150
# date -jf "%Y%m%d%H%M%S" $DATE "+date \"%A,%_d %B %Y %H:%M:%S\""
date "Saturday, 1 August 2009 20:41:50"

Hi Danmero thanks for the input. I need on one line, so I try to change as

date -jf "%Y%m%d%H%M%S" "20090801204150" "+date \"%A,%_d %B %Y %H:%M:%S\""

but I receive:
date: illegal time format

Maybe incorrect syntax?

:rolleyes: Works for me on bash/FreeBSD 7.2
For csh try:

# # date -jf '%Y%m%d%H%M%S' "20090801204150" '+date "%A,%_d %B %Y %H:%M:%S"'
date "Saturday, 1 August 2009 20:41:50"

and take a look at Mac OS X Manual Page For date(1), Sorry but I'm not a Mac user :wink: