The UNIX and Linux Forums  

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
Shell Script To increment Date*HElp*** niceboykunal123 Shell Programming and Scripting 1 04-23-2008 02:05 AM
Date Formatting in Shell Script Isiva UNIX for Advanced & Expert Users 2 07-10-2007 10:20 AM
Specify a previous date as start date in shell script ritzwan0 Shell Programming and Scripting 2 09-25-2006 06:58 PM
Shell script: last modification date for a file onlyc UNIX for Dummies Questions & Answers 4 07-06-2006 02:01 PM
How to subtract 2 hours from 'date' in shell ( /bin/sh ) script ? yairon UNIX for Dummies Questions & Answers 1 06-07-2001 04:23 PM

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 06-12-2007
royalibrahim royalibrahim is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 86
Identifying prior date in shell script

Hi guys,

I'm a newbie to shell script. I have to write a shell script that is supposed to give me a date which should be older than the current date when I supply "no. of days" as a command line parameter to the script.

(i.e)., if I am giving the no. of days value as 305, the script should give me the answer as date which is 305 days before today's date. The date can be in any format dd-mm-yyyy or mm/dd/yyyy, that is not a problem.

simply: (today's date – no of days) >>> should give the older date.

Looking forward to your "flooding" responses.

Thanks
  #2 (permalink)  
Old 06-12-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
In this post you will find all sort of date manipulation:
Yesterdays Date/Date Arithmetic
  #3 (permalink)  
Old 06-12-2007
royalibrahim royalibrahim is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 86
Hi thanks for the prompt response, I'll go through it. Meanwhile if someone has any inline scripts, pls don't hesitate to post it across. Thanks a lot once again.
  #4 (permalink)  
Old 06-16-2007
grumpf grumpf is offline
Registered User
  
 

Join Date: May 2006
Posts: 101
shell date conversion

hi royalibrahim,
take a look at gnu-date. it has some very powerfull date conversion built-in.
You can say stuff like:
date -d "10 day ago"
what make scripts very readable (as long you understand english).
I use the -d option very often to convert different date formats from programm to something our database likes.
  #5 (permalink)  
Old 06-22-2007
royalibrahim royalibrahim is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 86
Very useful info. Thanks a lot !!!
  #6 (permalink)  
Old 12-04-2008
royalibrahim royalibrahim is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 86
GNU date problem

Hi, I have come across this weird behaviour of GNU date.


Code:
date -d "21-May-08 09:29 1 minute" +"%d-%b-%y %H:%M"

gives output: 21-May-08 09:30 --> Note: I have given here the abbreviated month name format specifier '%b'

But,
Code:
date -d "21-05-08 09:29 1 minute" +"%d-%m-%y %H:%M"

gives output: 08-05-21 09:30 --> I mean the year and the date field is jumbled, though I have given the correct format specifier '%m' for the month field. How to make it work?
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

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 05:36 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