Yesterday's Date if it is Sunday


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Yesterday's Date if it is Sunday
# 1  
Old 05-15-2013
Yesterday's Date if it is Sunday

Hi All,

Can you please let me know how to get the yesterday's date of the given date if the given date is Sunday?
I can't use GNU. I have the code to get the yesterday's date based on the system date.

Thanks
# 2  
Old 05-15-2013
Can you tell us what Operating System you are using. Some have excellent date functions built in, if you know how to call them. Others less so, but there are ways around it.



Robin
Liverpool/Blackburn
UK
# 3  
Old 05-15-2013
Take a look at this link. You might get some pointers.
# 4  
Old 05-15-2013
explore these options...and add a if loop to check for the weekday
Code:
date '+%A'  #Prints whole weekday eg:Wednesday
date '+%u'  #Prints 1-7 (Mon to Sun)
date '+%w'  #Prints 0-7 (Sub to Mon)

# 5  
Old 05-16-2013
We are using AIX. I have used Perderabo's datecalc. Was wondering is there any short code. For time being I 'm using database to get this going.

Thanks
# 6  
Old 05-16-2013
With AIX, there is a neat trick with the time zone you can do.
Assuming you have this:-
Code:
$ echo $TZ
GMT0BST
$ date
Wed 15 May 12:04:36 2013

You can:-
Code:
$ TZ=GMT24BST
$ date
Wed 15 May 12:05:07 2013

You may have to work out how to slot the appropriate value into the TZ variable. On AIX you can actually push it beyond 24 hours, so if you want 5 days ago (24x5=120 hours) you can :-
Code:
$ TZ=GMT120BST
$ date
Sat 11 May 12:06:38 2013

You will need to substitute your time zone and include the offset, so if you are EST5EDT (as in the man page example) you would be best with:-
Code:
$ TZ=EST29EDT

to go back 24 hours.



Does that feature help?



Robin

Last edited by rbatte1; 05-16-2013 at 08:18 AM.. Reason: Added condition about other time zones
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

How to append date to filename, but base it on yesterday's date?

Hello, I'd like to write a monthly archive script that archives some logs. But I'd like to do it based on yesterday's date. In other words, I'd like to schedule the script to run on the 1st day of each month, but have the archive filename include the previous month instead. Here's what I... (5 Replies)
Discussion started by: nbsparks
5 Replies

3. Shell Programming and Scripting

How to get tomorrow,yesterday date from date Command

Hi I want to get tomorrow and yesterday date from date command. My shell is KSH and server is AIX. I tried several options, but unable to do. Please help on this. Regards Rajesh (5 Replies)
Discussion started by: rajeshmepco
5 Replies

4. Shell Programming and Scripting

[Solved] Replace yesterday date with today's date except from the first line

Hello, I have a file like this: 2012112920121130 12345620121130msABowwiqiq 34477420121129amABamauee e7748420121130ehABeheheei in case the content of the file has the date of yesterday within the lines containing pattern AB this should be replaced by the current date. But if I use... (3 Replies)
Discussion started by: Lilu_CK
3 Replies

5. Shell Programming and Scripting

How to derive the last Sunday's date when Current date value is passed

Hi All, I have a requirement in my project where a batch runs on any day of a week. The input files will land to the server every Sunday. I need to read these files based on the current BUS_DAY (which falls any day of the week). For e.g : if the BUS_DAY is 20120308, we need to derive the... (3 Replies)
Discussion started by: dsfreddie
3 Replies

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

7. Shell Programming and Scripting

Last sunday of current date

Hi Please help me with this problem i need to find the date of last week sunday from the current given date (12 Replies)
Discussion started by: aishsimplesweet
12 Replies

8. Shell Programming and Scripting

Compare date from db2 table to yesterday's Unix system date

I am currently running the following Korn shell script which works fine: #!/usr/bin/ksh count=`db2 -x "select count(*) from schema.tablename"` echo "count" I would like to add a "where" clause to the 2nd line that would allow me to get a record count of all the records from schema.tablename... (9 Replies)
Discussion started by: sasaliasim
9 Replies

9. UNIX for Dummies Questions & Answers

How to find last sunday (date) using perl?

How to find last sunday (date) using perl? Eg, If i run today (26-Feb-2008 / Tuesday), I should get 24-Feb-2008 (Sunday). Any help? (3 Replies)
Discussion started by: deepakwins
3 Replies

10. Shell Programming and Scripting

Date - Last Sunday thru Saturday

Hi All, I have to kick off a script on every Monday to get some data from database for last week (Sunday thru Saturday). If its Monday (12/12/2005) Begin date will be Sunday - 12/4/2005 End date will be Saturday - 12/10/2005 The script might not kick off on some Mondays. So my... (2 Replies)
Discussion started by: skymirror
2 Replies
Login or Register to Ask a Question