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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help needed with date chris1234 UNIX for Dummies Questions & Answers 16 03-31-2008 04:15 PM
Help Needed in Date Condition !! ranga27 Shell Programming and Scripting 24 03-28-2008 09:24 AM
help needed in date format ali560045 Shell Programming and Scripting 1 01-14-2008 10:05 AM
Help needed - Replacing all date & time occurrences in a file with a string using Sed Hema_M Shell Programming and Scripting 4 11-17-2005 01:42 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-06-2006
nikunj nikunj is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 3
Help needed on Date command

Hi,

I am facing one problem with date command.Actually I want to use this command to get the last month,not the current month..OK,I can do current month - 1 and give special condition for january,But this time i need last month as strings like January,februaury,march etc...
There is option available to get the month in the string form and that is
`date +%B` but this will give you the current month.
I can definitely do what i want with 12 cases one for each month but i want to avoid that.Please help me if anyone has any idea to implement this with out using 12 conditions.

Thanks,
-Nikunj
  #2 (permalink)  
Old 07-06-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,762
Yesterdays Date/Date Arithmetic

Perderabo's datecalc script is what you need to look at.
  #3 (permalink)  
Old 07-07-2006
grumpf grumpf is offline
Registered User
  
 

Join Date: May 2006
Posts: 101
get your self gnu date if you do not have it already. it actualy makes a readable script.

date
Fr Jul 7 17:47:56 CEST 2006

date -d"1 month ago"
Mi Jun 7 17:48:21 CEST 2006

since i learned about this some year ago i drop all date hacks (do you know what you can do with $TZ ?
  #4 (permalink)  
Old 07-08-2006
nikunj nikunj is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 3
Thanks grumpf,
Actaully i was looking for some similar options if i could..But the problem is I am using SunOs 5.8 and i am not authorized to add any package to the server.I tried this command and it didn't work..
It seems you have done lot of stuff on date command,Can you tell me is there any way to use date command to read from some variable not from the system,I mean if i can give my inputs to date command with out disturbing any system configurations?

Thanks in advance..
  #5 (permalink)  
Old 07-08-2006
System Shock's Avatar
System Shock System Shock is offline Forum Advisor  
Registered User
  
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 521
One way of doing it is with an array.

Code:
set -A YEAR January February March April May June July August September October November December

MONTH=$(date +%m)

if (( ${MONTH} == 1 )); then
MONTH=11
else
let MONTH=${MONTH}-2
fi

echo "This month is July, so last month was "${YEAR[${MONTH}]}
  #6 (permalink)  
Old 07-08-2006
nikunj nikunj is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 3
Thanks System Shock,

It seems it is the best way to do,I didn't know that we can have array too in a shell script,Thank you very much to make me aware of this.
Closed Thread

Bookmarks

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:49 PM.


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