Alex Rivera | Logout

Pipe string to GNU Date for conversion - how to make it read from stdin?

Asked 2012-01-05T12:26:56.570
34

GNU Date lets you convert date strings like so:

$ date +"%d %m %Y" -d "yesterday"
  04 01 2012

Is it possible to pipe a date string to it for conversion? I've tried the obvious -d - like so:

$ echo "yesterday" | date +"%d %m %Y" -d -

but it prints today's date instead of yesterdays.

Is it possible to pipe values to it or doesn't it support that?

Thanks.

Edit
Report

1 Answer

32

Yes.

 echo "yesterday" | xargs date +"%d %m %Y" -d
answered 2012-01-05T12:28:51.480

Your Answer