Validate date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Validate date
# 1  
Old 09-09-2005
Question Validate date

Hi

I am beginner to UNIX. I wanted to help for how to write script to validate date.

Please help me.
# 2  
Old 09-09-2005
Use the forum's search engine.

Look at these posts.
One
Two
# 3  
Old 09-15-2008
or try this little script Smilie

-----------------------------------------------


#!/usr/local/bin/zsh
# tested on FreeBSD 6.2
# max. logical date: 203801181201
# simple to use, example -> # validate.sh 19790231

date=$1

if [[ ! "$date" = ([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]) ]]
then
echo "input incorrect, \"ccyymmdd\""
exit 1
fi

if [ "$date" -gt "20380118" ]
then
echo "date invalid"
exit 1
else
testdate=`date -j "$date"1201 "+%Y%m%d"`
if [ "$testdate" -eq "$date" ]
then
exit 0
else
echo "date invalid"
exit 1
fi
fi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Validate date and time in filename by awk

hi i want to validate the date and time in filename filename : mohan.moh.ccyymmdd.ccyymmdd.hhmmss.txt mohan_moh.20151222.20151222.122442.txt i want code that check that date given in filename 20151222 in this format ccyymmdd else it mark file is not valid used in my OS detail is AIX 6... (12 Replies)
Discussion started by: MOHANP12
12 Replies

2. Shell Programming and Scripting

Validate date file format using awk

Here is my sample data Test.txt column 1|columne 2|start Date|end Date test|test|03/24/2014|03/24/2014 test|test|03/24-2014|03/24/2014 test|test|03/24/2014|03/24/2014 test|test|03/24/2014|03/24-2014 test|test|03/24/2014|03/24/2014 Now in the file i am expecting the date fields should be... (4 Replies)
Discussion started by: krish2014
4 Replies

3. Shell Programming and Scripting

Need script to validate file according to date

Hi All, I am very new to unix and just started to work with unix and shell scripting.I have a query anyone help would be much appreciated I am using sun solaris OS I want to validate a file according to its date and if validate successful then it would write the file name,size,date and... (3 Replies)
Discussion started by: sv0081493
3 Replies

4. Shell Programming and Scripting

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each certificate and send the mail to the user. The user takes action to add the new certificate to the storage file and user owns the responsibility to update the input text file with the new certificate... (5 Replies)
Discussion started by: casmo
5 Replies

5. Shell Programming and Scripting

validate date pattern using Regular Expression

Hi, i am java guy and new to unix. I want to validate date pattern using Regex expression here is the sample program i have written. #!/bin/sh checkDate="2010-04-09" regex="\\d{4}-\\d{2}-\\d{2}\$" echo $regex if ] then echo "OK" else echo "not OK" fi But the ouput is... (2 Replies)
Discussion started by: vvenu88
2 Replies

6. Shell Programming and Scripting

Validate date format in argument

Hi.. I'm a newbie in KSH. Need help. How can I validate input date format in argument using format mm/dd/yy. Eg. > findlog.sh 12/30/09. Any info/help is highly appreciated. (3 Replies)
Discussion started by: harry0013
3 Replies

7. Shell Programming and Scripting

Need to validate a date input format

Hi all, I have a shell script(K shell) which takes a date as input. i want the input to be in DD-MM-YYYY format. Can i enforce such a format of input string using just one line of code? OR do i need to parse the input date into different components and test them using Case statements... (2 Replies)
Discussion started by: rajugp1
2 Replies

8. Shell Programming and Scripting

Validate long date format in If statement

Hi, I want to validate if the given input is a valid month (written in long month format) Jan / Feb / Mar / Apr / May / Jun etc etc This is what I've got with || (or statements): #!/usr/bin/ksh INPUT_DATE=$1 FORMATTED_DATE=`date | cut -f2 -d' '` #If there's no input use the... (1 Reply)
Discussion started by: Batsies
1 Replies

9. Shell Programming and Scripting

How to Validate

I have one script by which I am taking Extraction Schedule in the following format ,,,...... Here I want validate the Input from user is okey or not. Let say i have one variable SCH SCH=12:34,23:12,11:20 Could you please tell me how I will validate it. HH & MM Both should be Numeric HH... (10 Replies)
Discussion started by: SanjayLinux
10 Replies

10. Shell Programming and Scripting

validate

hi need help here, a bit of code im doing requires a number to be enetered i have got validation and loop if its outside a ceratain range, but was wondering what code i need to validate if a character has been entered. cheers (3 Replies)
Discussion started by: ruffenator
3 Replies
Login or Register to Ask a Question