Date - Last Sunday thru Saturday


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date - Last Sunday thru Saturday
# 1  
Old 12-09-2005
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 question is, if I ran a script today (12/9/2005) how do I find the date of last Saturday (end date) and Sunday (begin date) before last.

I trided to use cal.

Thanks
# 2  
Old 12-09-2005
Look for my datecalc script on this site. You will need it. Then you can do:

$ datecalc -j $(( $(datecalc -j 2005 12 12) - $(($(datecalc -d 2005 12 12)+7-6)) ))
2005 12 10

To explain that...

"datecalc -d 2005 12 12" returns a day-of-week number for the given date. It uses the same scheme as cron..0=sunday 6=saturday. To find out how may days ago the last saturday was we add 7 (days in a week) and subtract 6 (saturday is day 6 in this scheme.

"datecalc -j 2005 12 12" returns a modified julian day number for the given date. 2005-12-12 happens to be 53,716. Each date has a different mjd number. To find the date n days ago, we just subtract n from the mjd. Then we convert the newly computed mjd back to a date.

Be sure to read the "Date Arithmetic" article in our FAQ section. And my datecalc script has built-in help. Just do "datecalc -help".

And the preceding Sunday is always 6 days earlier then the Saturday. Once you have the Saturday you should be able to calculate the Sunday pretty easily.
# 3  
Old 12-12-2005
Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

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 (5 Replies)
Discussion started by: shash
5 Replies

2. Shell Programming and Scripting

Run cron on every second Saturday ??

Hi, Can anyone help in editing CRON (OR) write a script to run another script every second saturday?? I tried to make use of DATE command to find the day but couldnt proceed further. your help is highly appreciated! Thanks, Mahi (11 Replies)
Discussion started by: mahi_mayu069
11 Replies

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

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

5. Windows & DOS: Issues & Discussions

How to get next Saturday's 'Date'?

Hi am trying to get the upcoming Saturday date in the batch file. Kindly help ASAP. its urgent. :confused: (10 Replies)
Discussion started by: Zensar
10 Replies

6. Shell Programming and Scripting

recurrence for every sunday for Date::MAnip in perl

Hi, I have a requirement to define all Saturdays/Sundays of every month in a year as holidays. I am making use of Date::Manip package available in perl. I tried writing a recurrence as : 0:1*3:7:0:0:0 --> this relation helps me to define 3rd Sunday of a year as sunday. My requirement is... (1 Reply)
Discussion started by: harpreetanand
1 Replies

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

8. Shell Programming and Scripting

Searching for a file, with name Last Sunday through Saturday

Hi List, I need write a script that looks for a file with name File_03-09_to_03-15_data.txt (File_LastSunday_to_LastSaturday_data.txt). If this file is not exists i have to look for a pervious weeks file like File_03-02_to_03-08_data.txt. This loop should continue untill it get a file or no file... (0 Replies)
Discussion started by: rejirajraghav
0 Replies

9. Solaris

How to check for Saturday or Sunday

Hi , I have a date parameter passed in YYYYMMDD format , how can I check whether it is Sat or Sun on Solaris box , as we can do the same easily on linux box by using date -d YYYYMMDD '+a' . Any pointres will be really helpful . (5 Replies)
Discussion started by: harpreetanand
5 Replies

10. Shell Programming and Scripting

Check if a day eg: saturday is the Last saturday of the month!

Hi, I need to develop a script to check for the day. If the day is a Saturday then the script should check if the Saturday is the last Saturday of the month so that certain set of instruction can be executed is it is the last Saturday. I do not want to use the crontab as this needs to be part... (9 Replies)
Discussion started by: jobbyjoseph
9 Replies
Login or Register to Ask a Question