Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using date to get tomorrows date in Bash

Tags:

bash

shell

unix

I want to write a bash script that will run on a given but process data with next days date, My current approach is to get the unix time stamp and add a days worth of seconds to it, but I cant get it working, and haven't yet found what I'm looking for online.

Here's what I've tried, I feel like the problem is that its a string an not a number, but I dont know enough about bash to be sure, is this correct? and how do I resolve this?

today="$(date +'%s')"

tomorrow="$($today + 86400)"

echo "$today"

echo "$tomorrow"
like image 972
Cob50nm Avatar asked May 14 '15 10:05

Cob50nm


People also ask

How can I get tomorrow date in Linux?

If you don't have GNU date, you can use the built-in date command with the -v option. returns tomorrow's date. returns tomorrow's date in the format YYYY-MM-DD.

How do I get the next day date in UNIX?

Moving Date Using the Day of Week Itemsdate --date='this Fri' ## OR ## date --date='next Fri.

How can I get yesterday's date in bash?

To get yesterday's date in bash shell you can use the Linux GNU date version with date -d yesterday or the Unix/macOS date version using date -j -v -1d .


1 Answers

If you have gnu-date then to get next day you can just do:

date -d '+1 day'
like image 170
anubhava Avatar answered Oct 10 '22 19:10

anubhava