LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-19-2009, 03:55 AM   #1
tucs_123
LQ Newbie
 
Registered: Dec 2008
Posts: 23

Rep: Reputation: 15
Need help for date validation


Hi,

I am accepting date as input parameter to my script.

>script_name 10/12/2008

The format of date is:MM/DD/YYYY.

How can I validate the entered date is in correct format or not?


Thanks in advance...........
 
Old 02-19-2009, 07:39 AM   #2
alan_ri
Senior Member
 
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
Set MM to be 13,if your script returns the error then it's working and the format is OK.

Last edited by alan_ri; 02-20-2009 at 06:57 AM. Reason: grammar
 
Old 02-20-2009, 02:14 AM   #3
Udi
Member
 
Registered: Jan 2009
Posts: 165

Rep: Reputation: 44
Alan_ri - I think that tucs_123 is the person writing the script, and he needs to know how to make the validation and not just test if the script knows how to validate dates.

There are probably many ways to skin this cat, but I would use 'cut' to split the input argument by the "/" separator and check the range of the day (1-31), month (1-12) and year (1970-):

month=`echo $1 |cut -d/ -f1`
day=`echo $1 |cut -d/ -f2`
year=`echo $1 |cut -d/ -f3`

if [ "$day" -ge 1 ] && [ "$day" -le 31 ] && [ "$month" -ge 1 ] && [ "$month" -le 12 ] && [ "$year" -ge 1970 ]; then
echo "format seems OK"
fi
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting system date and time affecting the clock and date on BIOS satimis Ubuntu 7 09-21-2007 08:02 AM
what is the correct syntax order for tar with --after-date DATE, --newer DAT farhan Linux - General 1 03-16-2007 08:43 AM
Date Validation in java using Patterns Manashi Programming 2 07-31-2006 07:19 AM
simple date validation in PHP tooparam Programming 1 04-08-2006 01:50 PM
JavaScript inside a CGI for date validation....doesn't work!! vous Programming 3 08-27-2003 04:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration