| | |
Date Validation again
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 23
Reputation:
Solved Threads: 0
I want a sample Date validation script using if loops.
The script should first compare "year".If the year is lesser than the current year,It should go for "month" checking.
I have the script that splits the date into year,month and date.I want only the checking part.
My if loop checking is not work properly.
Can you show the right way of checking?
Regards
Dave
The script should first compare "year".If the year is lesser than the current year,It should go for "month" checking.
I have the script that splits the date into year,month and date.I want only the checking part.
My if loop checking is not work properly.
Can you show the right way of checking?
Regards
Dave
Show what you have, and we will help you correct it.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Oct 2007
Posts: 23
Reputation:
Solved Threads: 0
This is the splitting part am having:
C_Date=`date -u +%m/%d/%Y`
year="$(echo $Date | cut -d/ -f3)"
month="$(echo $Date | cut -d/ -f1)"
day="$(echo $Date | cut -d/ -f2)"
cyear="$(echo $C_Date | cut -d/ -f3)"
cmonth="$(echo $C_Date | cut -d/ -f1)" cday="$(echo $C_Date | cut -d/ -f2)"
C_Date is current date i.e Today's Date.
#Validation
if [ $year -gt $cyear ]; then
echo "year out of range"
fi
Similarly am checking for month and day.Is there any other simple way to do the comparison using case Statement?
Regards
Dave.
C_Date=`date -u +%m/%d/%Y`
year="$(echo $Date | cut -d/ -f3)"
month="$(echo $Date | cut -d/ -f1)"
day="$(echo $Date | cut -d/ -f2)"
cyear="$(echo $C_Date | cut -d/ -f3)"
cmonth="$(echo $C_Date | cut -d/ -f1)" cday="$(echo $C_Date | cut -d/ -f2)"
C_Date is current date i.e Today's Date.
#Validation
if [ $year -gt $cyear ]; then
echo "year out of range"
fi
Similarly am checking for month and day.Is there any other simple way to do the comparison using case Statement?
Regards
Dave.
•
•
Join Date: May 2004
Posts: 178
Reputation:
Solved Threads: 10
date -u causes UTC date/time to be displayed - FYI.
If you format date like this: [code]
today=$(date +%Y%m%d)
you get a value like 20080111, this is a number - an integer.
When you split the input reformat it:
then compare integers:
If you format date like this: [code]
today=$(date +%Y%m%d)
you get a value like 20080111, this is a number - an integer.
When you split the input reformat it:
Shell Scripting Syntax (Toggle Plain Text)
newdate="$cyear$cmonth$cday"
Shell Scripting Syntax (Toggle Plain Text)
if [[ $today -ne $newdate ]] then echo "bad date" fi
![]() |
Similar Threads
- Any help with a Defult Value and Validation RULE. **MICROSOFT ACCESS** (MS Access and FileMaker Pro)
- Microsoft Access date validation Need a solution (Computer Science)
- need date validation help (MS Access and FileMaker Pro)
- Microsoft Access date validation Need a solution (Database Design)
- Hi Access Date Problem (> Now +7 Days And < Now +2 Months) (Computer Science)
- Microsoft Access date validation (Computer Science)
Other Threads in the Shell Scripting Forum
- Previous Thread: Need help in setting up as script..
- Next Thread: Begginer with Linux here nid help
| Thread Tools | Search this Thread |






