How to check if date format is correct?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check if date format is correct?
# 1  
Old 01-05-2013
Linux How to check if date format is correct?

Hi! how do i know if the input is the same as the required date format? the date should be dd/mm/YYYY ex. 2/3/2012 or 15/11/2012

all the following conditions must return an error:
*input of string
*day is > 31 or < 1
*month is > 12 or < 1
*year is < 2013

suppose the date format is stored in a variable start_date. i want it to be something like:
start_date="some code here"
so that i can do the following if condition:
Code:
if input == start_date
   echo "correct format!"
else
   echo "incorrect format!"

tnx in advance for the answers Smilie

Last edited by angilulu; 01-05-2013 at 01:31 PM.. Reason: typo error
# 2  
Old 01-05-2013
Have you tried searching these forums yet?
A good start would be the list of 'hints' at the bottom of this thread (More UNIX and Linux Forum Topics You Might Find Helpful)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to check date format DDMMYYYY

Record: Record1|Record2|Record3|Record4|Record5|DATE1|DATE2 Need to Check DATE1 & DATE2 is in DDMMYYYY format in a file. records which not meet the date format DDMMYYYY extract to other file. (1 Reply)
Discussion started by: vivekn
1 Replies

2. Shell Programming and Scripting

How to check user entered correct file format or not?

Hi Experts, path=/db/files/ format=$1 User can enter any file format.compare the user file format with actual file format existed in the directory /db/files. User enter all characters as "A" apart from date format. example1: user will be entering the file format AAA_AA_YYYYMMDD.AAA Actual... (6 Replies)
Discussion started by: nalu
6 Replies

3. Shell Programming and Scripting

Check Date Format And Email Out

Hello All, I have a requirement where i need to get the EXTRACT_DATE from a file and check if the date is of valid format or not and then mail it if it is not valid. Appreciate if you can help me with this. I did the following so far. awk '{for(i=1;i++<=NF;)if($i~/^EXTRACT_DATE/) print $i}'... (11 Replies)
Discussion started by: Ariean
11 Replies

4. Shell Programming and Scripting

perl script to check the mail ids in the correct format or not

Hi Folks, I have few mailids in a text file and need to check whether the mailid is in correct format or not. If just to check whether the string is a mailid or not there is a perl module Email::Valid to do the business or we can implement our own logic. But the mail_ids I am having is... (4 Replies)
Discussion started by: giridhar276
4 Replies

5. Shell Programming and Scripting

finding date numeral from file and check the validity of date format

hi there I have file names in different format as below triss_20111117_fxcb.csv triss_fxcb_20111117.csv xpnl_hypo_reu_miplvdone_11172011.csv xpnl_hypo_reu_miplvdone_11-17-2011.csv xpnl_hypo_reu_miplvdone_20111117.csv xpnl_hypo_reu_miplvdone_20111117xfb.csv... (10 Replies)
Discussion started by: manas_ranjan
10 Replies

6. Shell Programming and Scripting

Need to check date format yyyymm

My source file having one date column. The formate of the date column is yyyymm. I need to validate whether all the rows are in same format in the given file. If it is not I have captured that records in a separate file. I am very new to Unix. I don't how to achieve this. Plz help me to achieve... (2 Replies)
Discussion started by: suresh01_apk
2 Replies

7. Shell Programming and Scripting

Exit if date not in correct format

Can somone take a look at this script for me - I'm trying to get it to exit if the format of dateToLookFor is not in the format YYYYMMDD: function search { cd $logsloc echo "Enter date in format YYYYMMDD (enter to exit):" read dateToLookFor echo $dateToLookFor | grep -q ... (2 Replies)
Discussion started by: rich@ardz
2 Replies

8. Shell Programming and Scripting

Check input date format?

how to check input date format. for example $input_date must be in format dd.mm.gg script is execute like this: bin/script1.sh 14.12.2009 script1.sh code: #!/bin/sh input_date=$1 CMD="/app/si/test/test.sh $input_date" echo "*****" $CMD (2 Replies)
Discussion started by: waso
2 Replies

9. Shell Programming and Scripting

Check the format of Date

Hi, I have a date field in my input file. I just want to check if its in the format "DD-MM-YYYY". Is there any command which can achieve this? Thanks and Regards, Abhishek (2 Replies)
Discussion started by: AAA
2 Replies

10. Shell Programming and Scripting

Check for the correct date format in UNIx

Hi All, I am getting two input from User for Date from the command prompt when my script is executed . The date format i am taking is : DD-MM-YYYY so is there any method in Unix to validate the two input date. There might be many cases for these two date to be invalid.... (1 Reply)
Discussion started by: rawatds
1 Replies
Login or Register to Ask a Question