The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-18-2008
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.........
Reply With Quote
Forum Sponsor
  #2  
Old 03-18-2008
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 791
check if you can find a solution here
Reply With Quote
  #3  
Old 07-18-2008
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.
Reply With Quote
  #4  
Old 07-18-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 567
What platform are you on...because GNU's date utility can do this for you quite easily.
Reply With Quote
  #5  
Old 07-18-2008
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.
Reply With Quote
  #6  
Old 07-18-2008
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.
Reply With Quote
  #7  
Old 07-19-2008
drl's Avatar
drl drl is offline
Registered User
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 550
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
date, datecalc, linux, shell script, solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0