Sort and compare file

If I have 3 kinds of files in directory DATA1:
FileA.20060315.dat, FileB.20060315.dat, FileC.20060315.dat
FileC.20060316.dat
FileA.20060317.dat, FileB.20060317.dat
FileA.20060318.dat, FileB.20060318.dat, FileC.20060318.dat

If 3 files have the same date then run
$cat FileA.20060315.dat FileB.20060315.dat FileC.20060315.dat > FileD.20060315.dat and move these files to DATA2 .

if it doesnot have 3 files the same date then move it to DATA3 ???
How do you know what date to choose ?

#!/bin/ksh
cd  ./DATA1

for file in *.dat; do
ls -1 $file|awk -F"-" '{
        filedt = substr($2,1,8);
        {
    printf "%s\n",filedt
  }
        }'  >> checkit;
done
cat checkit | sort -n |uniq > date.srt

20060315
20060316
20060317
20060318
I get file sort by date then how I check date by date ? do you know ?

Try this:

#! /usr/bin/ksh

for i in FileA.* ; do
        if [[ -f FileB${i#FileA} && -f FileC${i#FileA} ]] ; then
                cat $i FileB${i#FileA} FileC${i#FileA} > FileD${i#FileA}
                mv $i FileB${i#FileA} FileC${i#FileA} FileD${i#FileA} ../DATA2
        fi
done
mv FileA.* FileB.* FileC.* ../DATA3 2>/dev/null
exit 0

wow, thanks, would you please explain for me the lines

if [[ -f FileB${i#FileA} && -f FileC${i#FileA} ]] ; then
cat $i FileB${i#FileA} FileC${i#FileA} > FileD${i#FileA}

I try to understand what does it mean.
if [[ -f FileB${i#FileA} && -f FileC${i#FileA} ]] --> if the fileB and file C have the same date with file A ???

FileB${i#FileA} = strip "FileA" off the front of the value of the variable, then prepend "FileB".