Print a date from 3 days ago

TZ=PST8PDT+72 date '+%Y_%m_%d'
This command prints the Date (Not time) from 3 days ago (72 hours ago). This works on systems without GNU date (MacOSX , Solaris, FreeBSD).
Sample Output
$ TZ=PST8PDT+72 date '+%Y_%m_%d'

2010-07-02 00:29:27

These Might Interest You

  • Might be more useful if you were able to print it in Days HH:MM:SS format as: perl -e '@p=gmtime(234234);printf("%d Days %02d:%02d:%02ds\n",@p[7,2,1,0]);' But I'm not exactly sure how to replace the 234234 with the output of the countdown time. (Having some problems with nested quoting/command substitution). Help would be appreciated :)

    watch --no-title -d -n 1 'echo `date -d "next Thursday" +%s` "-" `date +%s` | bc -l'
    jnash · 2009-03-29 06:53:09 4
  • Print out your age in days in binary. Today's my binary birthday, I'm 2^14 days old :-) . This command does bash arithmatic $(( )) on two dates: Today: $(date +%s) Date of birth: $(date +%s -d YYYY-MM-DD) The dates are expressed as the number of seconds since the Unix epoch (Jan 1970), so we devide the difference by 86400 (seconds per day). . Finally we pipe "obase=2; DAYS-OLD" into bc to convert to binary. (obase == output base) Show Sample Output

    echo "obase=2;$((($(date +%s)-$(date +%s -d YYYY-MM-DD))/86400))" | bc
    flatcap · 2015-10-19 15:40:32 0
  • Gets any date since today. Other examples of recognized expressions are "2 years 4 days ago", "7 months" (in the future), "next Sunday", "yesterday", "tomorrow", etc.

    date --date="90 days ago"
    dan · 2012-03-07 07:49:27 0
  • Line can be modified as needed. This considers weekdays to be Mon-Fri. If run any working day it'll provide a parameters for the next working day for "at". "beep" provided as a sample command. This can be modified easily to include wait time. If you need something to run "D" days after today: # D=4;if [ $(date +%u --date="${D} days") -lt 5 ];then AT="+${D} days";else AT="next monday";fi; echo "beep" | at noon ${AT}

    if [ $(date +%u) -lt 6 ];then AT="tomorrow"; else AT="next monday";fi;echo "beep" | at ${AT}
    eduo · 2011-06-01 14:15:11 2

What Others Think

why my console display 2010_07_01 in MacOSX10.6.4 OS?
fire9 · 415 weeks and 6 days ago
@fire9 : I'm not sure. It works for me on 10.5.8. Try '+24' instead of '+72'
StefanLasiewski · 415 weeks and 6 days ago
You can also use: date -d "-3 days" +%Y_%m_%d but I dont know if that will work on non gnu systems..
xeor · 415 weeks and 6 days ago
No, that will not work on non-GNU systems and that is exactly why this recipe is so good, so your attempt to help was kind of off the target. Everybody knows the date calculation capacities of GNU date (which don't apply to the regular UNIX date command) and the difficulties of working with dates on AIX/HP-UX/Solaris without perl.
Patola · 415 weeks and 4 days ago
@xeor : On non-GNU systems (MacOSX, *BSD, etc). The '-d' flag "SETS the kernel's value for daylight saving time." It *sets* the time.
StefanLasiewski · 415 weeks and 2 days ago
It worked for by changing PST8PDT to GMT, so the new command: TZ=GMT+72 date '+%Y_%m_%d'
ali980 · 346 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: