0

I am trying to find last day of the month. Date in DDMMYYYY format.

#!/bin/bash

start_date=01092018

end_date=$(date +%m%Y -d "$start_date +1 month")
echo $end_date

Expected Result :30092018

But it gives below error : Invalid character in date/time specification. Usage :date [-u] [+Field Descriptors]

Leon35
  • 25
  • 4
  • 1
    Aix!date doesn't know GNU extensions. You could use Perl for such calculations. Example: https://github.com/lzsiga/pldate `perl pldate set 20180901 add-month 1 printf %m%Y` – Lorinczy Zsigmond Dec 23 '19 at 13:42

1 Answers1

0

AIX date do not support -d. So you can't use constructions like date -d. For reference you can check AIX date man page

Nut you can try something in perl:

perl -MPOSIX -le '@x=localtime; if($x[4]!=0) {$x[4]++} else {$x[4]=11;$x[5]++};print strftime ("%Y-%m-%d", @x)'
Romeo Ninov
  • 6,538
  • 1
  • 22
  • 31