Use the /usr/sadm/bin/valdate command and check the return status. Examples: 
 
 
--GOOD DATE--
 
12322:oracle@e6500a> valdate -f "%e-%b-%Y" 1-jan-2001
12322:oracle@e6500a> echo $?
0
 
--BAD DATE--
 
12322:oracle@e6500a> valdate -f "%e-%b-%Y" 41-JaN-2001
12322:oracle@e6500a> echo $?
1
 
The valdate command doesn't seam to like leading 0's (zero's) so you can just use sed to strip it off.  This example should do most of what ya need:
 
12322:oracle@e6500a> cat dateck.ksh
#!/bin/ksh
vDATE="${1}"
if valdate -f "%e-%b-%Y" $(echo "${vDATE}" | sed "s/^0//")
then
  echo "Good date ${vDATE}"
else
  echo "Bad date ${vDATE}"
fi
 
 
12322:oracle@e6500a> dateck.ksh 41-mar-2001
Bad date 41-mar-2001
12322:oracle@e6500a> dateck.ksh 01-Mar-2001
Good date 01-Mar-2001
-----Original Message-----
From: Suhen Pather [mailto:[EMAIL PROTECTED]]
Sent: Thursday, October 25, 2001 8:00 PM
To: Multiple recipients of list ORACLE-L
Subject: date format in ksh

List,

 

Sorry to deviate from the topic, but

I am writing a korn shell script that would exit if the date format is

incorrect.

 

I just need something to compare the date format passed  in with DD-MON-YYYY.

 

Eg.

I am passing an argument to my ksh script being the date.

If the date is in any other format but DD-MON-YYYY the ksh must exit.

 

Eg.  sh test.ksh 02/05/1999

 

It must exit.

 

The only format excepted should be

sh test.ksh 02-MON-YYYY

 

TIA

 

Regards

Suhen

 

 

Reply via email to