given a date,find the next date


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users given a date,find the next date
# 1  
Old 12-06-2006
given a date,find the next date

Hi,
There are already some scripts posted in this forum reg date manipulations.This one is a addition to that.Go thro this script..
I didn't do any error checking (assuming that could be done in ano script)

# **** Finding date for a day after ****
#Add 1 to month, set date to 1 for the foll:
#if the date is 31
#if the date is 30, if the months are Apr, July, Sep or Nov
#if the date is 29, month is feb
#if the date is 29, month is feb and the year is leap year
#After addition, if the month is 13
#add 1 to year, set month to 1


#supply your date here
echo "28 02 4000"|
{
read DATE MONTH YEAR
incrementdate()
{
DATE=01
MONTH=`expr $MONTH + 1`
}
#check for date
case $DATE in
31)
incrementdate
;;
30)
if [ $MONTH -eq '04' -o $MONTH -eq '06' -o $MONTH -eq '09' -o $MONTH -eq '11' ]
then
incrementdate
fi
;;
29)
if [ $MONTH -eq '02' ]
then
incrementdate
fi
;;
28)
leapyr=`expr $YEAR % 4`
if [ $MONTH -eq '02' -a $leapyr -eq '0' ]
then
incrementdate
fi
;;
*)
DATE=`expr $DATE + 1`
;;
esac

#check for month
case $MONTH in
13)
#due to the above additions
MONTH=1
YEAR=`expr $YEAR + 1`
;;
esac

echo $DATE $MONTH $YEAR
}


# 2  
Old 12-06-2006
leapyr=`expr $YEAR % 4`

That will result in a leap year 100 times every 400 years which was correct for the Julian calendar. We now use the Gregorian calendar which has 97 leap years every 400 years. But don't take my word for it. Here is a link to Pope Gregory's bull, Inter Gravissimas.
# 3  
Old 12-07-2006
By default, in our calendar ..

By default, in our calendar every 4 years leap year ll occur. Right!
# 4  
Old 12-07-2006
Quote:
Originally Posted by sakthi.abdullah
By default, in our calendar every 4 years leap year ll occur. Right!
You are partially right because you said 4 years. But not every 4 years.

Years ending in 00 like 1700, 1800 are not leap years unless the year is also divisble by 400; i.e. 2000 was a leap year. 2100 will not be a leap year.

See what wikipedia has to say on leap years - http://en.wikipedia.org/wiki/Leap_year
# 5  
Old 12-07-2006
yes.. working on modifications
# 6  
Old 12-07-2006
This is a very common mistake. It is amazing how lucky we were that the year 2000 happened to be a leap year. 1900 and 2100 are far enough away from the current date that we often get away with it. It will be interesting to see how much stuff breaks in the year 2100. Smilie
# 7  
Old 11-11-2008
this will also fail at 28 th of any month

this will also fail at 28 th of any month
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Answers to Frequently Asked Questions

Compare date in .txt with system date and remove if it's lesser than system date

I m working on shell scripting and I m stuck where in my .txt file there is column as expiry date and I need to compare that date with system date and need to remove all the rows where expiry date is less than system date and create a new .txt with update. (1 Reply)
Discussion started by: Stuti
1 Replies

2. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date ‘19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

3. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

4. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

5. Shell Programming and Scripting

Converting a date to friday date and finding Min/Max date

Dear all, I have 2 questions. I have a file with many rows which has date of the format YYYYMMDD. 1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too. 2. After converting the date to... (10 Replies)
Discussion started by: 2001.arun
10 Replies

6. Shell Programming and Scripting

Date One Week Ago From Given Date, Not From Current Date

Hi all, I've used various scripts in the past to work out the date last week from the current date, however I now have a need to work out the date 1 week from a given date. So for example, if I have a date of the 23rd July 2010, I would like a script that can work out that one week back was... (4 Replies)
Discussion started by: Donkey25
4 Replies

7. Shell Programming and Scripting

How to find a date which is 7 days past when given current date

hii all. I have to get the date of the 7th day past from the current date. if i give the current date as sep 3 then i must get the date as 27th of august. can we get the values from the "cal" command. cal | awk '{print $2}' will this type of command work. actually my need is if today is... (17 Replies)
Discussion started by: ladtony
17 Replies

8. UNIX for Advanced & Expert Users

date issue-find prevoius date in a patricular format

Hi , I have written a shell script that takes the current date on the server and stores it in a file. echo get /usr/home/data-`date '+%Y%d'`.xml> /usr/local/sandeep/GetFILE.ini I call this GetFILE.ini file from an sftp program to fetch a file from /usr/home/ as location. The file is in... (3 Replies)
Discussion started by: bsandeep_80
3 Replies

9. Shell Programming and Scripting

Find julian date for given corresponding date

Hi, is there any possibility to find julian date for given corresping date. I will be gladfull if i get it. Requirement : Input : 10 09 2006 output: julian date: 283 thanks srikanth (2 Replies)
Discussion started by: srikanthus2002
2 Replies

10. UNIX for Dummies Questions & Answers

How to find Previous date and Coming date

Hi All, How to find a date which is 7 days from the current date as well as how to find a date which is 7 days before this current date. Urgently i need help. Thanks in Advance Regards Arunava (2 Replies)
Discussion started by: arunava_maity
2 Replies
Login or Register to Ask a Question