awk date and time validation

How can i validate if user inserted date and optionly a time is vaild but in awk scripting?

You're using awk to prompt the user for a date and time? Or you have the date and time somewhere (in a variable) and you want awk to validate it?

I got it wrong ,now i am asking how to validate a date and optionly a time in shell scripting (not in awk) when i get the date and time as pararmeters that sent out with the call of the file. (in my case sh union.sh `first parameter ,second parameter...`

What do first parameter and second parameter represent?

Here it is not important ,what is if that a date or time while the date with format of dd/mm and the time hh:mm:ss

Dear Tal,

You started out asking one thing. Now you are asking something else... maybe. Please give an example of what you expect to see happen. When you speak of validation, do you mean a date like 30/02 is invalid because February has only 28 (or 29) days?

To check if February connection to the year is ok ,the value of the day according to any month ,the value of the month and simularlly like this to do for the time.

Could somebody anwser?

-----Post Update-----

Could somebody anwser?

I know that in a foreign language, it is difficult to express exactly what you want.

You want input as "dd/mm". So today would be "02/06", correct? Then you want to make sure 02 is a valid day in 06?

Say you get "ddmm" and "hhmmss" as variables in your shell-script. (How you get them is up to you.)

DD=${ddmm%/*}
MM=${ddmm#*/}
hh=${hhmmss%%:*}
mmss=${hhmmss#*:}
mm=${mmss%:*}
ss=${mmss##*:}
echo $DD-$MM  $hh:$mm:$ss

So now you have it separated into parts. So now you just have to figure out if it's valid:

let invalid=0
case $MM in 
  02) 
          test $DD -le 29 || invalid=1 ;;
  0[469]|11) 
          test $DD -le 30 || invalid=1 ;;
  0[13578]|1[02]) 
          test $DD -le 31 || invalid=1 ;;
  *)
          invalid=1 ;;
esac

Note, I haven't tested this, so you better validate this before you use it in anything important.

What with the case of year that february has 28 days?

-----Post Update-----

IN did it could be 28 or 29.

-----Post Update-----

IN did it could be 28 or 29.

Yeah, but they're not providing the year.

In my script the year is taken automatically by the computer without any input needed of year.

Fine then. Just use standard algorithms to determine if the year is a leap year. If so, 29 is ok. If not, 28 is. Every 4 years from now is a leap year until 2100, which isn't.

You could use use touch...

$ if touch -t 0902290000 file1 2> /dev/null; then echo okay; else echo not valid; fi
not valid

$ if touch -t 0902280000 file1 2> /dev/null; then echo okay; else echo not valid; fi
okay

If using awk...

$ awk 'BEGIN{if(!system("touch -t 0902290000 file1 2> /dev/null")) print "okay"; else print "not valid"}'
not valid

$ awk 'BEGIN{if(!system("touch -t 0902280000 file1 2> /dev/null")) print "okay"; else print "not valid"}'
okay

Code:
DD=${ddmm%/}
MM=${ddmm#
/}
hh=${hhmmss%%:}
mmss=${hhmmss#
:}
mm=${mmss%:}
ss=${mmss##
:}
echo $DD-$MM $hh:$mm:$ss
So now you have it separated into parts. So now you just have to figure out if it's valid:

Code:
let invalid=0
case $MM in
02)
test $DD -le 29 || invalid=1 ;;
0[469]|11)
test $DD -le 30 || invalid=1 ;;
0[13578]|1[02])
test $DD -le 31 || invalid=1 ;;
*)
invalid=1 ;;
esac

I tested this procedure and it don't make the reqirured proccess ,duplicated the month and the day in one variable.

-----Post Update-----

-----Post Update-----

I have red this:
#!/usr/bin/ksh

string="abc@hotmail.com;xyz@gmail.com;uvw@yahoo.com"

oIFS="$IFS"; IFS=';'
set -A str $string
IFS="$oIFS"

echo "strings count = ${#str[@]}"
echo "first : ${str[0]}";
echo "second: ${str[1]}";
echo "third : ${str[2]}";

And i need to split a date and time in the following patern: 21/04 14:19:30 to 21 ,04 ,14, 19 ,30, but i don't want to use
oIFS="$IFS"; IFS=';'
and
IFS="$oIFS"
How can i do it?

-----Post Update-----

I have red this:
#!/usr/bin/ksh

string="abc@hotmail.com;xyz@gmail.com;uvw@yahoo.com"

oIFS="$IFS"; IFS=';'
set -A str $string
IFS="$oIFS"

echo "strings count = ${#str[@]}"
echo "first : ${str[0]}";
echo "second: ${str[1]}";
echo "third : ${str[2]}";

And i need to split a date and time in the following patern: 21/04 14:19:30 to 21 ,04 ,14, 19 ,30, but i don't want to use
oIFS="$IFS"; IFS=';'
and
IFS="$oIFS"
How can i do it?

-----Post Update-----

-----Post Update-----

Try...

$ echo '21/04 14:19:30' | awk 'BEGIN{FS="[^0-9]";OFS=", "};$1=$1'
21, 04, 14, 19, 30

Also...

$ if touch -t $(echo '21/04 14:19:30' | tr -dc "[0-9]") file1 2> /dev/null; then echo okay; else echo not valid; fi
okay

Again how can i split a tring to sub strings when the string for example is 21/4 to 21 ,4 and 14:20:06 to 14 20 06?

echo "21/04/2009 14:20:06" | awk -F"[:/]" '{ print $1 }'

That is the case in direction for the last replay i want a shell script to get from the user when it is called at least two strings then in the script pass it over to a awk script and to check how many arguments have been passed.
I use awk -F"[: /:]" to seperate the string that have been passed by the user to sub strings ,and i think using them in the awk script is ok of $1,$2...
How can i do it?