Work

Find A Future Date From The Shell

8:30AM April 29, 2009 | The How-To Geek

Have you ever needed the exact date a certain number of days in the future? The Command-Line Fu site shows how to use the date command to calculate future (and past) dates.

Using the date command is simple—just open a terminal window on your Mac, Linux, or Windows with Cygwin desktop, use the date command with the -d parameter, and pass in a number of date increments in the future in days, minutes, years, months, or even weeks. For instance, to find the date 3 weeks in the future, use the following command from the shell prompt:

date -d “3 weeks”

To find the date from a period of time in the past, you would add “ago” to the end of the command:

date -d “3 weeks ago”

You can even combine the arguments together—so if you wanted to find the exact date for 3 weeks and 2 days in the future, you would use:

date -d “3 weeks 2 days”

It’s a very simple tip, but for those of us that have a terminal window open at all times, it can really come in handy. For more geeky terminal tips, check out how to display a list of just the subdirectories, turn any Linux directory into an ISO file, or take a look through our top 10 command-line tools.

Date shows dates at other times/dates [Command-Line Fu]


Comments

  • Jo

    April 29, 2009 at 9:12 AM

    Really this is only setting the kernel’s offset for daylight savings.

  • Joshua

    February 3, 2011 at 10:50 AM

    This works on windows cygwin and on linux, but does not on Mac OS X. you have to do date -v +1d to do tomorrow. Commands like date -d tomorrow do not work on the Mac shell.

Post Your Comments