Friendz.. plz help me on this date function.


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Friendz.. plz help me on this date function.
# 1  
Old 03-18-2008
Question Friendz.. plz help me on this date function.

Smilie Hi there.
Hi frndz,
I have to script a shell in such a way that by giving the current date, it should give the previous saturday date and next sunday date as output.
eg: Input - 01-01-2008
O/p -
last saturady- 30-12-2007(ddmmyy)
Next Sunday- 05-01-2008

Please help me in finding hw to do do it..plz.........
# 2  
Old 03-18-2008
check if you can find a solution here
# 3  
Old 07-18-2008
I'm also looking for a shell script that will return the previous Saturday's date from any given date.

Tried to look everywhere but cannot find any solution. I don't want to use the existing datecalc function.

Thank you.
# 4  
Old 07-18-2008
What platform are you on...because GNU's date utility can do this for you quite easily.
# 5  
Old 07-18-2008
aix...

please provide example of GNU's date utility regardless and this might give me a clue.

Thank you.
# 6  
Old 07-18-2008
Please understand that I do not mean to distract from your desire for a script, but this is an excellent example, I think, of something which is bothersome with scripting but simple and straightforward with a C compiler. time(), localtime(), and the other date subroutines all give us excellent means to do this. perl or php also let you do fun things with dates. the UNIX "date" function kinda works with "now", unless of course you use the [-d|--date] option, but I don't see a simple way to make that work either. I had thought that if "date -d" would accept a julian date, then one could subtract a value related to the +%w value, but my CentOS 5 date program wouldn't take a julian date as input.

Sorry, I guess I just spoiled myself by writing C to do things like this. IMHO you might want to consider writing something in C, then using it as your date generator. If you are not comfortable with that, then perhaps perl or php might be helpful. Both are very powerful tools.
# 7  
Old 07-19-2008
Hi, pchang.
Quote:
Originally Posted by pchang
aix...

please provide example of GNU's date utility regardless and this might give me a clue.

Thank you.
Here are a few phrases date can understand and one that it cannot:
Code:
#!/bin/bash -

# @(#) s1       Demonstrate GNU date flexibility.

head -1 /etc/issue.net

echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version =o $(_eat $0 $1) date
set -o nounset
echo

echo " GNU date with English-like expressions:"
echo

date --date="2 weeks ago"
date --date="two weeks ago"

echo
date --date="today + 1 month"
date --date="3 years + 2 days"

exit 0

Producing:
Code:
$ ./s1
CentOS release 5 (Final)

(Versions displayed with local utility "version")
Linux 2.6.18-53.1.13.el5vm
GNU bash 3.1.17
date (GNU coreutils) 5.97

 GNU date with English-like expressions:

Sat Jul  5 15:55:46 CDT 2008
date: invalid date `two weeks ago'

Tue Aug 19 15:55:46 CDT 2008
Thu Jul 21 15:55:46 CDT 2011

As you can see, GNU date is extremely flexible.

I don't have access to an AIX box, but I suggest you look over man date to see if it has anything close ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Plz Help in sorting the data on date basis

I have file a.txt having below data cat a.txt 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-JUN-13 2.38.11.00.100089 IN 1514 0000764631 01-NOV-13 2.38.11.00.100089 IN 1514 0000856571 01-NOV-13 2.38.15.00.100015 IN 300.32 0000856531 01-JUN-13 2.38.19.00.100000 IN 2698 0000764493... (5 Replies)
Discussion started by: ranabhavish
5 Replies

2. UNIX for Dummies Questions & Answers

Plz Help in sorting the data on date basis

I have file having below data 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-JUN-13 2.38.11.00.100089 IN 1514 0000764631 01-NOV-13 2.38.11.00.100089 IN 1514 0000856571 01-NOV-13 2.38.15.00.100015 IN 300.32 0000856531 01-JUN-13 2.38.19.00.100000 IN 2698 0000764493 01-JUL-13... (2 Replies)
Discussion started by: ranabhavish
2 Replies

3. Shell Programming and Scripting

Need to Add date on first position.Plz help

We have a file as shown below with Header and details below Header.Here Header indicates date field. i Want to add date i.e 20100928 as a first position as shown below without header.Please help us using unix script Source file: H20100928 D04041201609360677PC790010384I ... (17 Replies)
Discussion started by: dprakash
17 Replies

4. Shell Programming and Scripting

Need-To remove header/trailor and add-date-on first-postion-plz-help

Hi Friends thanks a lot....for ur replies its worked fine...i have one more question.. if i need to remove trailor (T000000004 ) as shown below file also with header.Plz help thanks Source file: H20100928 D04041201609360677PC790010384I D04041203326357853PC790010645R ... (1 Reply)
Discussion started by: dprakash
1 Replies

5. Shell Programming and Scripting

Date function

I read man page for etc/shadow field.. on the 8th field, i assume that's the field to change account expire date. my question is: What value does the 8th field keep? i assume it's 13514 instead of "Date" value such as 11/10/08. on the man page, it said: " expire value = 13514 = jan 1,... (11 Replies)
Discussion started by: c00kie88
11 Replies

6. Shell Programming and Scripting

Date Function

Hi, My file format is: E102,0,21-04-2007,0,2/25/1994,E003,A,125400,10450,60.2884620 E103,0,21/04/2007,0,2/2/1996,E003,A,125400,10450,60.2884620 E104,0,04/21/2007,0,2/2/1996,E003,A,125400,10450,60.2884620 E105,0,21-APR-2007,0,2/2/1996,E003,A,125400,10450,60.2884620... (1 Reply)
Discussion started by: charandevu
1 Replies

7. Shell Programming and Scripting

Date Function

Hi, My file format is: E102,0,21-04-2007,0,2/25/1994,E003,A,125400,10450,60.2884620 E103,0,21/04/2007,0,2/2/1996,E003,A,125400,10450,60.2884620 E104,0,04/21/2007,0,2/2/1996,E003,A,125400,10450,60.2884620 E105,0,21-APR-2007,0,2/2/1996,E003,A,125400,10450,60.2884620... (1 Reply)
Discussion started by: charandevu
1 Replies

8. Shell Programming and Scripting

date function

hi, I have to ftp previous days file from a directory to another location. The name of the files are like "xxx20060225" (yyyymmdd format) "xxx20060226" ls -lrt xxx*| tail -2| head -1 will give me the file, but if i could get anything... (2 Replies)
Discussion started by: abey
2 Replies

9. UNIX for Dummies Questions & Answers

Date function question

hi guys! just want to ask if you could help me with the sript i'm working on. i need to automatically generate a summarized report everyday for all transactions the day before and ftp it to another machine. my only problem is that i need to name the file as the date yesterday. for example if i... (12 Replies)
Discussion started by: crpalermo
12 Replies

10. UNIX for Dummies Questions & Answers

plz Help How should I configure cc compiler output file plz help???

i.e configuration of C compiler :confused: (4 Replies)
Discussion started by: atiato
4 Replies
Login or Register to Ask a Question