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)
# 8  
Old 03-06-2010
Actually $0 represents the first command line argument. This will be usually a script name. $1 will be next argument and so on....
# 9  
Old 03-06-2010
Ok...
but given arguments may be unordered by such kind of users ,in that situation how can v handle?
# 10  
Old 03-06-2010
You need to compare each and every argument by for loop and if condition.
# 11  
Old 03-06-2010
You can get every thing about date in here...

https://www.unix.com/answers-frequent...rithmetic.html
# 12  
Old 03-06-2010
As stated above, this FAQ will tell you what you need for more complex date and date arithmetic: https://www.unix.com/answers-frequent...rithmetic.html

For this specific problem, you can just use the date command.

If you have the GNU version of date, just use:

Code:
date -d "yesterday" "+%Y%m%d"

If you have BSD, POSIX, Solaris version of date, here is a simple shell script that will do it.

Code:
#!/bin/bash

#call with (basename) 'YYYYMMDD' [+-deltadays]

#there is no error checking, use at your own use...

if [ ! -n "$1" ]
then
  echo "Usage: $(basename $0) YYYYMMDD [+-days]"
  exit $E_BADARGS
fi  

if [ ! -n "$2" ]
then
  	deltadays=-1
  else
	deltadays=$2
fi  


epoch=$(date -j -f "%Y%m%d" $1 "+%s")

(( deltadays *= 60*60*24 ))
(( epoch += deltadays )) 

newday=$(date -j -f "%s" $epoch "+%Y%m%d")

echo $newday

# 13  
Old 03-15-2010
THANKS FOR REPLAY...AND I GOT SOME IDEA FOR MY REQUIREMENT>>>

i need one more help....

if i have a string like aaaaa,bbbbb,ccccc,aaaaa

How to to split the string and check howmany times aaaaa will be in that string?
# 14  
Old 03-15-2010
Quote:
Originally Posted by karthinvk
THANKS FOR REPLAY...AND I GOT SOME IDEA FOR MY REQUIREMENT>>>

i need one more help....

if i have a string like aaaaa,bbbbb,ccccc,aaaaa

How to to split the string and check howmany times aaaaa will be in that string?
Please, don't piggy-back on existing threads - open a new thread for a new subject!
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