Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

format a number string to date

In a bash script, I have a variable like :

date=20140131

which means 31 Jan 2014. How can I add one day to it? I mean how can I add one value to "date" to change it to "20140201" (1 Fab 2014) not "20140132"

like image 660
gnome Avatar asked Aug 01 '26 15:08

gnome


1 Answers

with GNU date

$  d=20140131
$  date -d "$d +1 day" +%Y%m%d

20140201 

If you don't have gnu date, here is the script I used mostly (refer http://www.unix.com/16559-post2.html )

so if you need get the next day of 20140131, you can run:

datecalc -a 2014 01 31 + 1
like image 188
BMW Avatar answered Aug 03 '26 06:08

BMW



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!