i have a script called date_add.sh written in k_shell
My shell script requirement is that it accepts a date from the user in the format YYYY-MM-DD and then it shows all the 15 days later day availaible in the current year
if date accepted from user is 2008-10-13,then the o/p sholud be
2008-10-28
2008-11-12
2008-11-27
2008-12-12
2008-12-27
-----------------------------------------------------------------------
How to put this logic in a loop? Also how to convert Epoch days into format YYYY-MM-DD
Current_day=`perl -e 'print int(time/86400);'`--------------------16145
but the below command is not working
perl -e '@d=localtime ((stat(shift))[9]); printf "%4d-%02d-%02d\n", $d[5]+1900,$d[4]+1,$d[3]' Current_day
below my script . Actually in my script i m taking the current date and then adding 15 days to it.
--------------------------------------------------------------------------
#!/bin/ksh
Current_day=`perl -e 'print int(time);'`
echo $Current_day
count=0
count=`expr $Current_day + 1296000`
echo $count
perl -le 'print scalar localtime('"$count"');'
perl -e '@d=localtime ((stat(shift))[9]); printf "%4d-%02d-%02d\n", $d[5]+1900,$d[4]+1,$d[3]' '"$count"'
--------------------------------------------------------------------------
the last command that converts the $count value into format YYYY-MM-DD is not working . plz help me in this?
stat works on files, not epoch seconds.
ok. so how to convert the value of the below command into the formay YYYY-MM-DD so i should get the o/p as 2008-10-28
perl -le 'print scalar localtime('"$count"');'
#!/bin/ksh
tictock()
{
perl -e '
$now = time;
$increment = 1296000;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($now);
$year += 1900;
for($i=0, $thisyear = $year ; $thisyear==$year ; $i++)
{
printf ("%4d-%02d-%02d ", $year, $mon, $mday);
$incr=($increment * $i) + $now;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($incr);
$year += 1900;
$mon += 1;
}
'
}
set -A arr $(tictock )
let i=0
while [[ $i -lt ${#arr[*]} ]]
do
print ${arr}
i=$(( i + 1))
done
ali560045:
i have a script called date_add.sh written in k_shell
My shell script requirement is that it accepts a date from the user in the format YYYY-MM-DD and then it shows all the 15 days later day availaible in the current year
if date accepted from user is 2008-10-13,then the o/p sholud be
2008-10-28
2008-11-12
2008-11-27
2008-12-12
2008-12-27
-----------------------------------------------------------------------
. date-funcs
year=$( date +%Y )
_DATESHIFT=$1
while :
do
_dateshift $_DATESHIFT 15
[ ${_DATESHIFT%%-*} -ne $year ] && break
printf "%s\n" "$_DATESHIFT"
done
The date-funcs library of shell functions is available at The Dating Game .