inconsistent output using date()

I have an input list of:

I am just trying to turn this list into its seconds since epoch "+%s" time equivalent. I'm trying to use the following, but every time I run the command it gives me different answers, they are close, but never the same... any clues as to why?

xargs -I{} date -j -f "%m/%e/%Y %l:%M %p %Z" "{}" "+%s"

Definitely perplexed by this one. :wall: Any help would be greatly appreciated.

Oh, and I'm running this from Mac OS X on the command line.

Thanks!

Is that an upper %( eye ) or a lowercase %( ell ) for the hours? Should be the ell. Otherwise your syntax looks okay to me.

Please define "small differences". Also check to see if your bash has the strftime builtin.

It is an "ell" -- so I think that is good. I'm new to shell/bash, so forgive my ignorance, but how do I check to see if my bash has the strftime built in?

thanks

Don't have access to a Mac OS box anymore, but I can reproduce this under FreeBSD 7.2 and 8.2. It looks like the date command is substituting the current seconds into the value. When I run it close to a minute boundary, for one of your times, I get:

Your time: 2/10/2012 8:48 PM EST

DATE EXECUTED                   FROM DATE       WHAT THAT IS
Tue Feb 21 23:00:55 EST 2012    1328924935      2012/02/10 20:48:55
Tue Feb 21 23:00:57 EST 2012    1328924937      2012/02/10 20:48:57
Tue Feb 21 23:00:58 EST 2012    1328924938      2012/02/10 20:48:58
Tue Feb 21 23:00:59 EST 2012    1328924939      2012/02/10 20:48:59
Tue Feb 21 23:01:01 EST 2012    1328924881      2012/02/10 20:48:01

Where 'date executed' is the time I ran the command, 'from date' is the epoch time date returned, and 'what that is' is what the epoch time converts back into. Notice that the date, hours and minutes are all correct, but the seconds match the execution time.

Sounds like a bug in date to me.

You might try something like this which appends :00 to the time and then passes it to xargs.

sed 's/ PM/:00 PM/; s/ AM/:00 AM/' /tmp/t | xargs -I{} /bin/date -j -f "%m/%e/%Y %l:%M:%S %p %Z" "{}" "+%s"

EDIT: If it wasn't clear, /tmp/t was my file with the list of times.