The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Function to find day of any given date. RRVARMA Shell Programming and Scripting 5 05-12-2008 03:19 AM
Date Function charandevu Shell Programming and Scripting 1 04-02-2008 09:12 AM
Date Function charandevu Shell Programming and Scripting 1 04-02-2008 07:44 AM
Wrong date function Asteroid Shell Programming and Scripting 3 04-04-2007 04:09 AM
date function abey Shell Programming and Scripting 2 02-27-2006 05:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-18-2008
psn123 psn123 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1
Question Friendz.. plz help me on this date function.

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 (permalink)  
Old 03-18-2008
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
check if you can find a solution here
  #3 (permalink)  
Old 07-18-2008
pchang pchang is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 8
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 (permalink)  
Old 07-18-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
What platform are you on...because GNU's date utility can do this for you quite easily.
  #5 (permalink)  
Old 07-18-2008
pchang pchang is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 8
aix...

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

Thank you.
  #6 (permalink)  
Old 07-18-2008
fsahog fsahog is offline
Registered User
  
 

Join Date: Apr 2006
Location: Northern Virginia
Posts: 23
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 (permalink)  
Old 07-19-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 704
Hi, pchang.
Quote:
Originally Posted by pchang View Post
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
Sponsored Links
Closed Thread

Bookmarks

Tags
date, datecalc, linux, shell script, solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0