0

So I am writing a date calculation Bash and I am having issues with date format. Maybe I am just writing it wrong, any insite is helpful

#!/bin/bash

echo -e "bill date"
read date

      d1=$(date -d  "$date +27 days")
      d2=$(date -d  "$date +45 days" )


echo "$(tput bold setaf 3)Suspension date = $d1" 
echo "$(tput bold)$(tput setaf 1)Termination date = $d2"

What I would like is the output to be: Suspension date = Mon Nov 6 2017

what I get is Suspension date = Mon Nov 6 00:00:00 EST 2017

I have tried many variations of and placements of +'%a %B %d %Y' and I keep getting invalid date errors.

hitting my head against my desk and wall have not knocked anything loose so far.

1

Use a date format string:

d1="$(date -d "$date +27 days" +"%a %b %d %Y")"

This depends entirely upon the user inputting a format that is parseable by date -d.

  • I appeared to have been missing the outside " " and that is what was breaking everything, Thank you! – Amidues Nov 2 '17 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.