write script for previous date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting write script for previous date
# 1  
Old 08-18-2009
Data write script for previous date

Hi all,
I need to write a unix shell script that will return the previous date of date entered and i have to consider leap year also.

For eg:- if i entered 2009-08-18 then the script should return 2009-08-17

can you please help me to write this script.???Image
# 2  
Old 08-18-2009
Quote:
Originally Posted by prasson_ibm
Hi all,
I need to write a unix shell script that will return the previous date of date entered and i have to consider leap year also.

For eg:- if i entered 2009-08-18 then the script should return 2009-08-17

can you please help me to write this script.???Image
Did you tried any code..?
then we can see what approach u r using..
# 3  
Old 08-18-2009
Code:
#!/bin/ksh
timestamp=$(printf "%(%Y-%m-%d+%H:%M:%S)T" now) 
timeint=$(printf "%(%#)T" "$timestamp") 
((daysec=24*60*60)) 
((yesterday=timeint - daysec)) 

printf "yesterday %(%Y-%m-%d)T \n" "#$yesterday"

# 4  
Old 08-18-2009
Thanks for your reply, but can you please explain me what you doing in this script.
My requirment is to pass the date as the parameter and script should return the previous date
# 5  
Old 08-18-2009
add after 1st line, call script using date format yyyy-mm-dd
Code:
timestamp=$(printf "%(%Y-%m-%d+%H:%M:%S)T" now) 
[ "$1" != "" ] && timestamp=$(printf "%(%Y-%m-%d+%H:%M:%S)T" "$1+00:00:00")

# 6  
Old 08-18-2009
hi, thanks for your reply,i m trying to run this script on AIX box,but getting error...SmilieSmilie
# 7  
Old 08-18-2009
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

AIX UNIX - script on how to extract from log file with previous date

Hello, I am new to this forum so any assistance would help. I am currently trying to develop a script that extract all data from a log file with has the previous day's date. $ <root@aixtest3> /var/log > more sudo.log May 13 10:52:10 aixtest3 local2:notice sudo: tbrath : TTY=unknown ; ... (14 Replies)
Discussion started by: Kslew82
14 Replies

2. Shell Programming and Scripting

Script to get previous date for the given input date..

hi all, need a script or command to get the previous date for the given input date... like in my script i will pass date as input parameter like 2014-12-01 and i want the output as previous date.. ie.. 2014-11-30 (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

3. 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

4. Shell Programming and Scripting

How to find the date of previous day in shell script?

Hi Experts, i am using the below code get the date of previous day. #!/usr/bin/ksh datestamp=`date '+%Y%m%d'` yest=$((datestamp -1)) echo $yest When i execute the code i am getting output as: 20130715 What i am trying here is, based on the date passed i am fetching previus day's... (0 Replies)
Discussion started by: learner24
0 Replies

5. Shell Programming and Scripting

Help with getting last date of previous month and first date of previous 4th month from current date

I have requirment to get last date of previous month and the first date of previous 4th month: Example: Current date: 20130320 (yyyymmdd) Last date of previous month: 20130228 (yyyymmdd) First date of previous 4th month: 20121101 (yyyymmdd) In my shell --date, -d, -v switches are not... (3 Replies)
Discussion started by: machomaddy
3 Replies

6. Shell Programming and Scripting

finding the previous day date and creating a file with date

Hi guys, I had a scenario... 1. I had to get the previous days date in yyyymmdd format 2. i had to create a file with Date inthe format yyyymmdd.txt format both are different thanks guys in advance.. (4 Replies)
Discussion started by: apple2685
4 Replies

7. Shell Programming and Scripting

Script to check file with previous date

Hi all,I need your help to create the script.I need a script to check the ZIP file at network location with yesterday date name. ZIP file creation date is current date, but name of the zip file is previous date. for example file name "20110216.zip" created today 201102017.I just want to return the... (1 Reply)
Discussion started by: deepaksingla
1 Replies

8. Shell Programming and Scripting

to write a script to compare the file size in the current directory and previous dir

hi, i am new to this site. i want to write a script to compare the file size of the files in the current dir with the files in the previous directory. the files name will be same, but the filename format will be as xyzddddyymm.txt. the files will arrive with the month end date(i want to... (5 Replies)
Discussion started by: tweety
5 Replies

9. UNIX for Dummies Questions & Answers

script to write the last login date and time

I want to make a script to write me in a file the date(format 16-12-2008) and hour(format 15:12:21) of the last login in the system; what can i add to the <last> command in order to be suitable? (4 Replies)
Discussion started by: kalimat
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