Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


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

Rep: Reputation: 15
Need help for date validation


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, 08:39 AM   #2
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 07:57 AM. Reason: grammar
Old 02-20-2009, 03:14 AM   #3
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"


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 09:02 AM
what is the correct syntax order for tar with --after-date DATE, --newer DAT farhan Linux - General 1 03-16-2007 09:43 AM
Date Validation in java using Patterns Manashi Programming 2 07-31-2006 08:19 AM
simple date validation in PHP tooparam Programming 1 04-08-2006 02:50 PM
JavaScript inside a CGI for date validation....doesn't work!! vous Programming 3 08-27-2003 05:49 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:41 PM.

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