The Linux date command displays the current date and time of the system. While writing the shell scripts, I realise that sometimes we are required to find future dates—for example, dates after 10 days, 2 months, or 1 year, etc.

Advertisement

The date command provides an option to display the future dates as described.

-d, --date=STRING          display time described by STRING, not 'now'

Let’s understand this with some examples:

  • Display current date: Simply type “date” to display the current date and time of system.
    date     
    
    Thu Sep 22 03:58:36 UTC 2022
    
  • Date after 10 days: What will be the date after 10 days? The below command will show you the desired results:
    date -d "+10 days"
    
    Sun Oct  2 03:58:48 UTC 2022
    
  • Date after 3 months: Similarly to find the date after 3 months, type:
    date -d "+3 months "
    
    Thu Dec 22 03:58:58 UTC 2022
    
  • Date after 1 year: What will be the date just after 1 year?
    date -d "+1 year"
    
    Fri Sep 22 03:59:05 UTC 2023
    

These commands are helpful to find the day, month date in the future after a specific duration. We can also format the date on display. Here are a few more examples to view future dates and times.

CommandOutputDetails
dateThu Sep 22 03:58:36 UTC 2022Display the current date.
date -d “+10 days”Sun Oct 2 03:58:48 UTC 2022Display date after 10 days.
date -d “tomorrow”Fri Sep 23 03:58:48 UTC 2022Show tomorrow’s date
date -d “tomorrow + 1”Fri Sep 24 03:58:48 UTC 2022Show date of the day after tomorrow.
date +”%a” -d “+10 days”SunDispla the day name after 10 days (eg: Sun, Mon etc)
date +”%b %d, %Y” -d “+10 days”Oct 02, 2022Display date after 10 days in custom format
date -d “next sun”Sun Sep 25 00:00:00 UTC 2022Display date on next Sunday
date +”%b” -d “next month”OctShwo the next month name (eg: Oct, Nov etc)
date -d “next week”Thu Sep 29 04:46:32 UTC 2022Show the date on next week of same day
date -d “Oct 12, 2022 +1 week”Wed Oct 19 00:00:00 UTC 2022Date after 1 week of Oct 12, 2022(or other specific date)
date +”%A” -d “Oct 12, 2022 +1 week”WednesdayDisplay the day name after one week of Oct 12, 2022.
Share.

Leave A Reply