![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Function to find day of any given date. | RRVARMA | Shell Programming and Scripting | 5 | 05-12-2008 12:19 AM |
| Date Function | charandevu | Shell Programming and Scripting | 1 | 04-02-2008 06:12 AM |
| Date Function | charandevu | Shell Programming and Scripting | 1 | 04-02-2008 04:44 AM |
| Wrong date function | Asteroid | Shell Programming and Scripting | 3 | 04-04-2007 01:09 AM |
| date function | abey | Shell Programming and Scripting | 2 | 02-27-2006 02:28 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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......... |
| Forum Sponsor | ||
|
|
|
#3
|
|||
|
|||
|
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
|
|||
|
|||
|
What platform are you on...because GNU's date utility can do this for you quite easily.
|
|
#5
|
|||
|
|||
|
aix...
please provide example of GNU's date utility regardless and this might give me a clue. Thank you. |
|
#6
|
|||
|
|||
|
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
|
||||
|
||||
|
Hi, pchang.
Quote:
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 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 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 |
||||
| Google The UNIX and Linux Forums |