Help needed-calculate previous date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed-calculate previous date
# 1  
Old 08-27-2008
Help needed-calculate previous date

Hi Friends,

Need a command/script in unix which calculates previous date [day -1] from current date.

For ex:
If current date= 01 Jan 2008, then output =31 Dec 2007
If current_date =01 Aug 2008 , then output= 31 July 2008

Please advice

Regards,
Suresh
# 2  
Old 08-27-2008
# 3  
Old 08-27-2008
try this

Quote:
Originally Posted by sureshg_sampat
Hi Friends,

Need a command/script in unix which calculates previous date [day -1] from current date.

For ex:
If current date= 01 Jan 2008, then output =31 Dec 2007
If current_date =01 Aug 2008 , then output= 31 July 2008

Please advice

Regards,
Suresh

Suresh,

I've been using this code in my shell-scripts. Try it if it works for you:

YDAY=`TZ=TAIST+16 date '+%Y%m%d'`

Smilie
# 4  
Old 08-29-2008
Hi Guys,

Thank you very much guys for the inputs
this command is working fine for me
TZ=TAIST date '+%Y%m%d'
20080829

Just wanna check this command once on 1st September to see if it retrives previous date correctly. Hope this command will work fine during year change over as well

-Thanks
Suresh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Date - incorrect results for previous date

Hello: I am bit puzzled with what I could be doing wrong and any help is appreciated. I have a date in YYYMMDD format and I need to find the previous date. Based on the input on this forum, I have come up with the following. It seems to work for all except the following. Here I am passing date... (3 Replies)
Discussion started by: wincrazy
3 Replies

3. AIX

Calculate needed CPUs

Hello If a process on a AIX system uses 0.3 CPU's, how many cpu's are needed for 100 Systems? Regards, Patrick (3 Replies)
Discussion started by: PatMis81
3 Replies

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

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

6. Shell Programming and Scripting

Improve script made to calculate value based on present and previous line

Hi all, I have made at small script to make a simple calculation on a file which is formatted in this way: I want to create a new file in which the value of particular line minus the previous line is printed. So my wanted output is: I have made the following program to do the job... (5 Replies)
Discussion started by: s052866
5 Replies

7. Shell Programming and Scripting

Pass the first date and last date of previous month

Hi All, I need to run a job every month at the beginning of the month which is scheduled through autosys, lets say on 03/01/2010. I need to pass the last month's i.e February's first_date = 02/01/2010 and last_date = 02/28/2010 as variables to a stored procedure. Can somebody please pass... (2 Replies)
Discussion started by: vigdmab
2 Replies

8. Shell Programming and Scripting

want to get previous date from date command in ksh

I want to get previous date from date command. I am using ksh shell. Exmp: today is 2008.09.04 I want the result : 2008.09.03 Please help. Thanks in advance. (4 Replies)
Discussion started by: rinku
4 Replies

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

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