[NTLUG:Discuss] Date format

Matt Cole matt at netcertification.com
Fri Mar 16 15:04:35 CST 2001


I'm trying to convert dates in a large datafile:

My dates are in the format:
Mar 1 2001  2:46PM
Mar 15 2001 12:30AM

I'm trying to convert them using the date command:

date -d 'Mar 16 2001  2:46PM' +"%b %e %Y %l:%M%p"

But I get:

invalid date `Mar 16 2001  2:46PM'

So, why can I do this:

date +"%b %e %Y %l:%M%p" 
(returns: Mar 16 2001  2:46PM)

but not this:

date -d 'Mar 16 2001  2:46PM' +"%b %e %Y %l:%M%p"
(returns:  invalid date `Mar 16 2001  2:46PM')


Can you only use certain formats when converting a string TO a date?

Interestingly, both of these work:

date -d "2:32PM" +"%l:%M%p"
(returns: 2:32PM)

date -d "Mar 16 2001" +"%b %e %Y"
(returns: Mar 16 2001)


But using a combination of these two doesn't work.

Any help is appreciated.

Matt




More information about the Discuss mailing list