Checking for future / non existent dates


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking for future / non existent dates
# 1  
Old 10-07-2007
Checking for future / non existent dates

'm attempting to script an application for the bash shell. The application needs to check for birthday, but must check the birthday to see if the date is a) in the future b) exists at all (ie Feb 29th during non-leap years). The input is being entered in a YYYYMMDD format, so I was hoping someone could point me in the direction for how to check for future dates and non-existent dates.

Thanks
- D
# 2  
Old 10-07-2007
Korn:
Code:
#! /usr/bin/ksh

DATE=$1
typeset -i day

eval $(echo $DATE | sed 's/^\(....\)\(..\)\(..\)/year=\1 month=\2 day=\3/')

cal $month $year 2> /dev/null | grep -w $day > /dev/null
if [[ $? -eq 0 ]] ; then
        echo "Valid Date"
else
        echo "Invalid Date"
fi

or same thing in bash
Code:
#! /bin/bash

DATE=$1
declare -i day

eval $(echo $DATE | sed 's/^\(....\)\(..\)\(..\)/year=\1 month=\2 day=\3/')

cal $month $year 2> /dev/null | grep -w $day > /dev/null
if [[ $? -eq 0 ]] ; then
        echo "Valid Date"
else
        echo "Invalid Date"
fi

# 3  
Old 10-09-2007
This script will validate the format and checks for the date availability in the calendar (thus solves leap year problem). But as the user expected it will not check whether the date falls on future or not. So the user has to take care of it in his script like this:

if [ "`date '+%Y%m%d'`" -ge "$DATE" ]; then
.....
fi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need simple script to generate future dates

Hi All, I am looking into a script which will give me a future dates for 7 days, including next month dates in case if runs on month ends... I an able to get this in Linux but not working for Solaris. OS: Solaris 10 Please help (6 Replies)
Discussion started by: nanz143
6 Replies

2. Shell Programming and Scripting

Shebang of non-existent interpreter not giving error

I read that whenever you provide wrong path at sha-bang it will generate an error with message "command not found", but when I run script with wrong path, it runs perfectly without generating any error. any reason ? #!/home/usrname/etc echo "hello" exit 0 (4 Replies)
Discussion started by: Qazi
4 Replies

3. Red Hat

Postfix - want to send email to some non-existent user using alias

Hi, I know how to use email redirection using /etc/aliases file + postfix combination and it is working fine for existing users. The question I have is: I want to send an email to tony@server1.example.com while tony user is actually not there. Rather, I want to redirect that email to... (0 Replies)
Discussion started by: freebird8z
0 Replies

4. Shell Programming and Scripting

Create a directory when its non-existent

Hi I need to create a directory when its non-existent Having an issue with the code here because it doesn't work can someone point what and how to change, please. ---------- Post updated at 11:08 AM ---------- Previous update was at 11:07 AM ---------- filelist=project_name/files/... (7 Replies)
Discussion started by: murari83.ds
7 Replies

5. UNIX for Dummies Questions & Answers

How to write the dates between 2 dates into a file

Hi All, I am trying to print the dates that falls between 2 date variables into a file. Here is the example. $BUS_DATE =20120616 $SUB_DATE=20120613 Output to file abc.txt should be : 20120613,20120614,120120615,20120616 Can you pls help me accomplish this in LINUX. Thanks... (5 Replies)
Discussion started by: dsfreddie
5 Replies

6. Shell Programming and Scripting

Creating a directory if its non-existent within a script

Hi, is there a way to create a directory when its non-existent when trying to move files to this particular folder? Thanks much. (7 Replies)
Discussion started by: ida1215
7 Replies

7. Shell Programming and Scripting

Future dates.

If I have a script that writes the name of the file based on today, tomorrow, and the day after tomorrow. How would I modify the line echo "filename.${PDY}${CYC}" >>CONTROL to reflect tomorrow and the day after tomorrow and write it to the file called CONTROL? Since ${PDY} shows... (2 Replies)
Discussion started by: libertyforall
2 Replies

8. Shell Programming and Scripting

Need script to generate all the dates in DDMMYY format between 2 dates

Hello friends, I am looking for a script or method that can display all the dates between any 2 given dates. Input: Date 1 290109 Date 2 010209 Output: 300109 310109 Please help me. Thanks. :):confused: (2 Replies)
Discussion started by: frozensmilz
2 Replies

9. Shell Programming and Scripting

To get previous or future dates based on input value

Hi, I need something like, if the input date is 24/Aug/2008 and the inputvalue is +8 then the result should be 1/Sep/2008 (8 days after the input date) if the input date is 24/Aug/2008 and the inputvalue is -8 then the result should be 16/Aug/2008 (8 days before the input date) is there any... (5 Replies)
Discussion started by: Sharmila_P
5 Replies

10. Shell Programming and Scripting

add or modify if existent

I want to set these params in /etc/system set shmsys:shminfo_shmmax=2000000000 set shmseg:shminfo_shmseg=200 if this param exists, then I want to modify them if not, I want to add them. I can add them using >>/etc/system but how to do the modify thing? at least I can comment the... (4 Replies)
Discussion started by: melanie_pfefer
4 Replies
Login or Register to Ask a Question