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, I need to get the last date of previous month sirrtuan Shell Programming and Scripting 11 10-14-2008 05:59 AM
KSH Checking Previous Date** developncode UNIX for Dummies Questions & Answers 4 04-17-2008 12:42 PM
want to create directory with the previous date sridhusha Shell Programming and Scripting 7 11-19-2007 05:44 AM
Specify a previous date as start date in shell script ritzwan0 Shell Programming and Scripting 2 09-25-2006 05:58 PM
How to find Previous date and Coming date arunava_maity UNIX for Dummies Questions & Answers 2 05-24-2001 11:41 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 06-28-2006
Nayanajith Nayanajith is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 27
Get the Previous date

Dear all,

I want to echo the previous date every time whrn i run a script

eg -

./test.sh

result-

Today is - 2006 06 29
Yesterday is - 2006 06 28

exactly like this.

How to do this ....?

Thanks,
Nayanajith.
  #2 (permalink)  
Old 06-29-2006
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
If you're using GNU date (as on Linux systems,) you can do somthing like:
date -d yesterday
to get "now - 24 hours"

If you're not, you can use the wonderful datecalc script provided by Perderabo:
http://www.unix.com/unix-dummies-questions-answers/4870-days-elapsed-between-2-dates.html#post16559
  #3 (permalink)  
Old 06-29-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
Code:
$ cat test.sh
#! /bin/ksh
a=`date +%y%m%d`
b=`TZ=CST+24 date +%y%m%d`
echo "Today is $a"
echo "Yesterday was $b"
NOTE: Command, `TZ=CST+24 date +%y%m%d` for yesterday's date I found at some thread, on the same board.

If you have GNU date avaialbe it has more powerful features.


Regards,
Tayyab
Sponsored Links
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:44 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