Aksh
Aksh

Reputation: 15

Calculating next day's date for special cases of end of month dates

I'm working on a script that takes a date in the format YYYMMDD as an input:

#!/bin/bash
check_dir () {
  d1=$2
  d2=$((d1+1))
  f1=`mktemp`
  f2=`mktemp`
  touch -d $d1 $f1
  touch -d $d2 $f2
  n=$(find $1 -mindepth 1 \( -name "*$d1*" \) -o \( -newer $f1 ! -newer $f2 \) | wc -l)
  if [ $n != $3 ]; then echo $1 "=" $n ; fi
  rm -f $f1 $f2
}

In this script d2=$((d1+1)) calculates the next day's date from the date provide i.e., d1. But, what if the date is 20151231, then it will not be able to handle this situation. Could anyone please help me how to handle this exception?

gdate does not work on my platform!!

Upvotes: 0

Views: 24

Answers (1)

flederwiesel
flederwiesel

Reputation: 461

With the date version from GNU coreutils (i.e. used in Linux):

$ date -d '20151231 +1 day' +'%Y%m%d'
20160101

Upvotes: 1

Related Questions