[mythtv-users] Calculating date forward and date back with the date command

Jeff C myth at express.tc
Thu Apr 29 12:27:49 EDT 2004


Its not often that I discover something very cool and easy on Unix, but this
one is too good not to share.  And two of my favorite hard core Unix people
didn't know about it, so I thought I'd pass it along.  Of course I only
found it because I haven't graduated past shell scripting yet...  

I have discovered that the date command can do forward and reverse date
calculations for you, right on the command line.  Given that there are whole
perl modules devoted to this, I was happy to see it is easier than I
thought.

I'm running debian so YMMV but:

mythtv at mythtv:~ $ date "+%Y%m%d"
20040429
mythtv at mythtv:~ $ date "+%Y%m%d" --date=3D"9 days"
20040508
mythtv at mythtv:~ $ date "+%Y%m%d" --date=3D"9 days ago"
20040420
mythtv at mythtv:~ $

This is especially useful when you don't have a native grabber for XMLTV and
you are trying to compile from different sources and using tv_split and
tv_sort and so forth and you need to be able to ID the correct output file
from tv_split.

Hope that saves someone some else time too.

-Jeff




More information about the mythtv-users mailing list