Identifying prior date in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Identifying prior date in shell script
# 1  
Old 06-12-2007
Identifying prior date in shell script

Hi guys,

I'm a newbie to shell script. I have to write a shell script that is supposed to give me a date which should be older than the current date when I supply "no. of days" as a command line parameter to the script.

(i.e)., if I am giving the no. of days value as 305, the script should give me the answer as date which is 305 days before today's date. The date can be in any format dd-mm-yyyy or mm/dd/yyyy, that is not a problem.

simply: (today's date - no of days) >>> should give the older date.

Looking forward to your "flooding" responses.

Thanks
# 2  
Old 06-12-2007
In this post you will find all sort of date manipulation:
https://www.unix.com/showthread.php?t=13785
# 3  
Old 06-12-2007
Hi thanks for the prompt response, I'll go through it. Meanwhile if someone has any inline scripts, pls don't hesitate to post it across. Thanks a lot once again.
# 4  
Old 06-16-2007
shell date conversion

hi royalibrahim,
take a look at gnu-date. it has some very powerfull date conversion built-in.
You can say stuff like:
date -d "10 day ago"
what make scripts very readable (as long you understand english).
I use the -d option very often to convert different date formats from programm to something our database likes.
# 5  
Old 06-22-2007
Very useful info. Thanks a lot !!!
# 6  
Old 12-04-2008
GNU date problem

Hi, I have come across this weird behaviour of GNU date.

Code:
date -d "21-May-08 09:29 1 minute" +"%d-%b-%y %H:%M"

gives output: 21-May-08 09:30 --> Note: I have given here the abbreviated month name format specifier '%b'

But,
Code:
date -d "21-05-08 09:29 1 minute" +"%d-%m-%y %H:%M"

gives output: 08-05-21 09:30 --> I mean the year and the date field is jumbled, though I have given the correct format specifier '%m' for the month field. How to make it work?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare Date to today's date in shell script

Hi Community! Following on from this code in another thread: #!/bin/bash file_string=`/bin/cat date.txt | /usr/bin/awk '{print $5,$4,$7,$6,$8}'` file_date=`/bin/date -d "$file_string"` file_epoch=`/bin/date -d "$file_string" +%s` now_epoch=`/bin/date +%s` if then #let... (2 Replies)
Discussion started by: Greenage
2 Replies

2. Linux

How to calculate the quarter end date according to the current date in shell script?

Hi, My question is how to calculate the quarter end date according to the current date in shell script? (2 Replies)
Discussion started by: Divya_1234
2 Replies

3. Shell Programming and Scripting

Shell script to compare two files of todays date and yesterday's date

hi all, How to compare two files whether they are same are not...? like i had my input files as 20141201_file.txt and 20141130_file2.txt how to compare the above files based on date .. like todays file and yesterdays file...? (4 Replies)
Discussion started by: hemanthsaikumar
4 Replies

4. UNIX for Dummies Questions & Answers

How to write a shell script to Run it the from Date A to Date B?

Hi , How would i write a shell script to run the code from one date to another date EXample 2014-01-01 to 2014-02-28, can i any provide some clue on this (4 Replies)
Discussion started by: vikatakavi
4 Replies

5. Shell Programming and Scripting

Need help in Shell Script comparing todays date with Yesterday date from Sysdate

Hi, I want to compare today's date(DDMMYYYY) with yesterday(DDMMYYYY) from system date,if (today month = yesterday month) then execute alter query else do nothing. The above requirement i want in Shell script(KSH)... Can any one please help me? Double post, continued here. (0 Replies)
Discussion started by: kumarmsk1331
0 Replies

6. Red Hat

identifying SU mode by shell script

the following bash script is not working in fedora-11 Could anyone help me please? #!/bin/bash if -ne 0];then echo " you are in root" else echo " you must be in root -su mode??" fi exit (2 Replies)
Discussion started by: Turtel
2 Replies

7. Shell Programming and Scripting

How to increment a user defined date value in the DATE format itself using shell script?

I need to increment a date value through shell script. Input value consist of start date and end date in DATE format of unix. For eg. I need increment a date value of 1/1/09 to 31/12/09 i.e for a whole yr. The output must look like 1/1/09 2/2/09 . . . 31/1/09 . . 1/2/09 . 28/2/09... (1 Reply)
Discussion started by: sunil087
1 Replies

8. Shell Programming and Scripting

script to retrieve file for prior day

Is there a way to Create file name for the prior Sunday of the run_date if my Run_date =05262009, i need to the file with the File name= filename.Y20090524.zip Thanks in advance (1 Reply)
Discussion started by: aronmelon
1 Replies

9. Shell Programming and Scripting

Delete lines prior to a specific date in a log file.

Hi all. I have a database log file in which log data get appended to it daily. I want to do a automatic maintainence of this log by going through the log and deleting lines belonging to a certain date. How should i do it? Please help. Thanks. Example. To delete all lines prior to Jun... (4 Replies)
Discussion started by: ahSher
4 Replies

10. Shell Programming and Scripting

Specify a previous date as start date in shell script

Hi, I am trying to modify a script which accepts date in format dd/mm/yy. I am trying to modify the script so that it retrieves the date that was 15 days earlier from today as start date. Eg.if today is 05/09/2006, the script should retrieve 21/08/2006 as start date. Is there any script/code to... (2 Replies)
Discussion started by: ritzwan0
2 Replies
Login or Register to Ask a Question