Below is the script.There are steps which could have clubbed with other steps but I kept them separate for clarity.See if this script helps you.
###############################################################################
#Usage : scriptname.sh directoryname
#Purpose: this script takes last modified file from directory.Directory is passed
# as an argument while calling script and report if file is older or newer than last 24 hrs
#logic: step1 list last modified file
# step2 Take last modified time of the file by parts
# step3 convert last modified time of file and system time into seconds
# step4 take diff of two times and check for 24 hrs.
###############################################################################
#############################################
#month_to_num function takes Month name as
#argument and return index value of month
#############################################
month_to_num() {
if [ -n "$1" ]
then
t_month=$1
case $t_month in
Jan) return 01;;
Feb) return 02;;
Mar) return 03;;
Apr) return 04;;
May) return 05;;
Jun) return 06;;
Jul) return 07;;
Aug) return 08;;
Sep) return 09;;
Oct) return 10;;
Nov) return 11;;
Dec) return 12;;
*) return 0;;
esac
fi
}
#############################################
####################################
modf_time=`ls -ltr "$1" | tail -1`
##################################
#BElow commands take Hr min Yr month day individually
#retuned by long listing of last file
time_month=`echo $modf_time | awk '{print $6}'`
time_day=`echo $modf_time | awk '{print $7}'`
time_hrmin=`echo $modf_time | awk '{print $8}'`
time_hr=`echo $time_hrmin | cut -d ':' -f1`
time_min=`echo $time_hrmin | cut -d ':' -f2`
filename=`echo $modf_time | awk '{print $9}'`
#assuming system time year and file modified year are same
century=`date '+%Y'`
#converts month Name to numeric number
month_to_num $time_month
v_month_index=$?
echo "month index $v_month_index"
filedatetemp="${century}-${v_month_index}-${time_day} ${time_hr}:${time_min}"
#converts file time to seconds
filedate=`date --utc --date "$filedatetemp" +%s`
#converts system time to seconds
sysdate=`date '+%Y-%m-%d %H:%M' | date '+%s'`
diffSec=$((sysdate-filedate))
if [ $diffSec -le 0 ]
then abs=-1
else abs=1
fi
x=$((diffSec/abs))
# 24 hr in secs =24*60*60 sec
if [ $x -le 86400 ]
then
echo "File $filename is newer than 24 hrs"
else
echo "File $filename is older than 24 hrs"
fi