Find the next day from 20100303 (YYYYMMDD format)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find the next day from 20100303 (YYYYMMDD format)
# 1  
Old 03-05-2010
Find the next day from 20100303 (YYYYMMDD format)

Hi ,
i have doubt in bash shell script..
for example my file name is sampledate.sh
given command = ./sampledate.sh -d 20100303 -f karthi
how to find the next day from 20100303 (YYYYMMDD format)
After getting the next day ,changed date and -f argument value will be sent to one java class.

waiting for your response
Thanks
------

Last edited by karthinvk; 03-05-2010 at 11:26 PM..
# 2  
Old 03-06-2010
If you want the next date you can use the following way

Code:
full_date=$2
date=${full_date:4:2}
let next_date=$date+1;
if [ $next_date -lt 9 ]
then
        next_date="0"$next_date #adding trailing zeroes
fi
echo $next_date;


Last edited by thillai_selvan; 03-06-2010 at 12:57 AM..
# 3  
Old 03-06-2010
Hai Thillai,Karthi has clearly mentioned the date format in his post itself.Did you read it fully before you answer?Thillai,I think your solution won't be correct.Because,if the day number is 30 or 31,what happens,check it out?In your case,it simply incremented by 1.Then,the day will be 32 or 31.Whether it is expected?
# 4  
Old 03-06-2010
Hai vivek! Thanks for your feedbacks! Actually I pointed the sample way of getting the next date.
I have given the basic the ideas only.
We are not here to write code from A-Z for the user's complete requirement.
We need to give the basic ideas.
That basic idea should make the poster to think in writing the code.
Here lot of stuffs should be achieved.
We need to check the month values. Because alternate months will have the last dates as 31,30,31,30 etc.
And also For the feb month also we need to consider.
If the date count is reached the last date for the particular month we need to increment the month count.
If the month count is reached 12 then we need to increment the year count
And we need to consider the leap year's Feb days.
Lot of stuffs are there.
I pointed the basic things about extracting the next date from the given command line argument.
Have you got my point?

Last edited by thillai_selvan; 03-06-2010 at 01:01 AM..
# 5  
Old 03-06-2010
Yeah Thillai,nice of you.But,it is better to mention before which means in your first reply itself.
# 6  
Old 03-06-2010
Hi

thanks for reply

You mentioned $2 for getting date right?
but run time if i give
./sampledate.sh -f karthi -d 20100303 means wat ll happen?
# 7  
Old 03-06-2010
You need to change that as $2 to $4.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to conver YYYYMMDD to MJD format?

I would like to convert YYYYMMDD to MJD format for eg 20041223 converted to 53362 in MJD format i got logic from javascript to covert it to MJD which is long enough function YMDtoMJD (year, month, day) { var year; var monthi var day; var yr = Math.floor (year); ... (1 Reply)
Discussion started by: mandalmanas24
1 Replies

2. Shell Programming and Scripting

Date format to be changed from DDMMYYYY to YYYYMMDD

My requirement is:- there will be files at a location each day with the date format DDMMYYYY. Novawise_Activity_Call_Notes_04022013.txt Novawise_Activity_Inbound_04022013.txt Novawise_Activity_Inbound_05022013.txt Novawise_Activity_Call_Notes_05022013.txt... (8 Replies)
Discussion started by: djrulz123
8 Replies

3. Shell Programming and Scripting

Validating date in yyyymmdd format using PERL

Hi all, i had a code where in user will enter a date in yyyymmdd format.. i didnt use any validation for the date and now the problem is if a user enters date instead of month after year it is proceeding with the code.. like if the date is 20120426 and if the user enters 20122604 it... (4 Replies)
Discussion started by: smarty86
4 Replies

4. Shell Programming and Scripting

Find first created file date in YYYYMMDD format

Hi All, We are copying all the files into ARCHIVE directory after we process them. We are doing this process from last 2 years, now we have a lot of files in ARCHIVE directory. Now I need to find when the first file is copied into this directory? If I Issue, ls -l /ARCHIVE/*.* | tail -1... (3 Replies)
Discussion started by: Raamc
3 Replies

5. Solaris

Date after 5 dates in YYYYMMDD format

Hi Experts, How to get date 5 days after current date in YYYYMMDD format? How do we compare date in YYYYMMDD format? Thanks (1 Reply)
Discussion started by: needyourhelp10
1 Replies

6. Shell Programming and Scripting

convert date format YYYYMMDD to MM/DD/YYYY

In my shell script i have a variable which stores date in the format of YYYYMMDD. Is there any way to format this value to MM/DD/YYYY. Thanks. (8 Replies)
Discussion started by: nasirgondal
8 Replies

7. UNIX for Dummies Questions & Answers

Format date from MM/DD/YYYY to YYYYMMDD

I have a file with some date columns in MM/DD/YYYY format: SMPBR|DUP-DO NOT USE|NEW YORK||16105|BA5270715|6/6/2007 |MWERNER|109||||JOHN||SMITH|MD|72211118||||||74559|21 WILMINGTON RD||D|11/6/2003|SL# MD CONTACT-LIZ RICHARDS|||0|Y|N||1411458| And I want to convert the date format to: ... (5 Replies)
Discussion started by: ChicagoBlues
5 Replies

8. Shell Programming and Scripting

get yesterday in yyyymmdd format

how can i get yesterday in yyyymmdd format? :confused: (13 Replies)
Discussion started by: aaron_fong
13 Replies

9. HP-UX

How can i get the yesterday's date in YYYYMMDD format

How can i get the yesterday's date in YYYYMMDD format??? (4 Replies)
Discussion started by: prasadsr
4 Replies

10. UNIX for Dummies Questions & Answers

get yesterday date in yyyymmdd format

I would like to know how I could get a yesterday date in yyyymmdd e.g. today is 20011109, and I would like to get 20011108. Thank you!:confused: (2 Replies)
Discussion started by: hk_newbie
2 Replies
Login or Register to Ask a Question