Date shows dates at other times/dates

date -d '2 weeks ago'
Use date to find the date at other days and times.

By: Buzzcp
2009-04-28 03:09:23

These Might Interest You

  • The match pattern only matches ISO 8601 dates of the form YYYY-MM-DDTHH:mm:SS.sssZ Show Sample Output

    sed "s|\(2[0-9]\{3\}-[01][0-9]-[0-3][0-9]T[01][0-9]:[0-5][0-9]:[0-5][0-9].[0-9]\{3\}Z\)|$(date -d \1 +%s)000|g"
    anthonyf · 2012-06-03 14:50:12 0
  • remotely connects to an https site, fetches the ssl certificate and displays the valid dates for the cert

    echo | openssl s_client -connect 2>/dev/null |openssl x509 -dates -noout
    systemj · 2009-02-05 15:21:50 3
  • On CentOS at least, date returns a boolean for the common date string formats, including YYYY-MM-DD. In the sample output, you can see various invalid dates returning 0 whereas a simple regex check would return 1 for the invalid dates. -d, --date=STRING display time described by STRING, not `now' The version of date on OS X does not appear to have this same option. Show Sample Output

    if date -d 2006-10-10 >> /dev/null 2>&1; then echo 1; else echo 0; fi
    SteveGoossens · 2013-01-10 10:35:15 0
  • 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

What Others Think

Other examples: date -d tomorrow #24 hours from now date -d '400 minutes' #400 minutes from now date -d '-3 days -2 hours -10 minutes' #more specific time increments in the past.
Buzzcp · 477 weeks ago
This is slightly different on FreeBSD: date -v-2w Which means minus two weeks. You could also ask for something like four hours ahead 3 days ago. date -v-3d -v+4H
claytron · 477 weeks ago
hi friends i am taking two weeks is as than it shoud be given new image -------------- lisa --------------- [url=]online dating[/url]-online dating
manoj87 · 469 weeks and 6 days ago
hi friends this a gud genration for casuality side. ---------- manoj --------------- [url="
manoj87 · 469 weeks and 6 days 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: