Time comparison

hi friends,
I am new to shell scripting and i am using KSH shell .I would like to automate our daily routine manual tasks .first i ll explain the situation .I will list out the contents of directory named "log" using "ls " and verify whether all the listed files time differences is not more than 30 minutes.if not, i will send the mail. Now , i need to automate this . i think i can take the time[for eg: 00:00 ,00:30,01:00,01:30....23:00] alone by using "awk" command or "date" function how can i compare the time values because i am having approximately[not exactly] 48 files[24/0.5] per day i need to check the time difference between above 48 files[for every 30 minutes once one file will be created ] .based on that i will do some other tasks...

           My time stamp is "Jan 28 18:48"
  
           Eg:  ls -l log
                 file 1 00:30                    file 2 - file 1 is 30 minutes
                 file 2 01:00                     
                 file 3 01:30                    file 3 - file 2 is 30 minutes

                 can anyone help me ? Thanks in advance .....

Here is one approach which works across midnight time change-

#!/bin/ksh

filetime()  # file time in epoch seconds
{
    perl  -e '          
          print (stat $ARGV[0])[9];
         ' $1
}

istooold()  # return 0 if too old, 1 if okay
{
	now=$(date +%s)       # epoch time in seconds
	ftime=$(filetime "$1")   # file age in seconds
	now=$( now - 1800 )   # 30 minutes ago 
	if [[ $ftime -ge $now ]] ; then
		print 1
	else
	    print 0
	fi	
}

for filename in  $(ls log)
do
	ok=$( istooold $filename)
	if [[ ok -eq 1 ]] ; then
	   echo "$filename is okay"
	else
	   echo "$filename is too old"
	fi   
done 

thanks guru .. i will try and let you know what is happening

That will break if any filenames contain spaces. But it won't work anyway, because the filenames will not contain the directory.

for filename in log/*