| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
|  |  | |||
Home -> Community -> Mailing Lists -> Oracle-L -> RE: date format in ksh
<SPAN 
class=456101422-29102001>Use the /usr/sadm/bin/valdate command and 
check the return status. Examples: 
<SPAN 
class=456101422-29102001> 
<SPAN 
class=456101422-29102001> 
<SPAN 
class=456101422-29102001>--GOOD DATE--
<SPAN 
class=456101422-29102001> 
<SPAN 
class=456101422-29102001>12322:oracle_at_e6500a> valdate -f "%e-%b-%Y" 
1-jan-200112322:oracle_at_e6500a> echo $?0
<SPAN 
class=456101422-29102001> 
<SPAN 
class=456101422-29102001>--BAD DATE--
<SPAN 
class=456101422-29102001> 
<SPAN 
class=456101422-29102001>12322:oracle_at_e6500a> valdate -f "%e-%b-%Y" 
41-JaN-200112322:oracle_at_e6500a> echo $?1
<SPAN 
class=456101422-29102001> 
<SPAN 
class=456101422-29102001>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:
<SPAN 
class=456101422-29102001> 
<SPAN 
class=456101422-29102001>12322:oracle_at_e6500a> cat 
dateck.ksh#!/bin/ksh
<SPAN 
class=456101422-29102001>vDATE="${1}"if valdate -f "%e-%b-%Y" $(echo 
"${vDATE}" | sed "s/^0//")then  echo "Good date 
${vDATE}"else  echo "Bad date ${vDATE}"fi
<SPAN 
class=456101422-29102001> 
<SPAN 
class=456101422-29102001> 
<SPAN 
class=456101422-29102001>12322:oracle_at_e6500a> dateck.ksh 41-mar-2001Bad 
date 41-mar-200112322:oracle_at_e6500a> dateck.ksh 01-Mar-2001Good date 
01-Mar-2001
  <FONT face=Tahoma 
  size=2>-----Original Message-----From: Suhen Pather 
  [mailto:Suhen.Pather_at_strandbags.com.au]Sent: Thursday, October 25, 
  2001 8:00 PMTo: Multiple recipients of list 
  ORACLE-LSubject: date format in ksh
  
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">List,
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Sorry to deviate from the topic, 
  but
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">I am writing a korn shell script 
  that would exit if the date format is
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">incorrect.
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">I just need something to compare 
  the date format passed  in with 
  DD-MON-YYYY.
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Eg. 
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">I am passing an argument to my ksh 
  script being the date.
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">If the date is in any other format 
  but DD-MON-YYYY the ksh must exit.
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Eg.<SPAN 
  style="mso-spacerun: yes">  sh test.ksh <st1:date 
  Year="1999" Day="5" Month="2"><SPAN 
  style="FONT-FAMILY: Arial">02/05/1999<FONT 
  face=Arial>
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">It must 
  exit.
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">The only format excepted should be 
  
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">sh test.ksh 
  02-MON-YYYY
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">TIA
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Regards
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Suhen
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 
  <SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 
Received on Mon Oct 29 2001 - 16:16:00 CST
|  |  |