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
Specify a previous date as start date in shell script ritzwan0 Shell Programming and Scripting 2 09-25-2006 05:58 PM
Get the Previous date Nayanajith Shell Programming and Scripting 2 06-29-2006 01:39 AM
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 Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-12-2006
rajus19 rajus19 is offline
Registered User
  
 

Join Date: Feb 2005
Location: Bangalore
Posts: 36
Previous day's date in Perl?

Hi All,

I want to find the previous day's date and store that in a variable, which will be usuful for further processing.

Any help please.

Regards,
raju
  #2 (permalink)  
Old 07-13-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
This is exactly what you want:
Code:
a=$(perl -w -e '@mytime=localtime (time - $ARGV[0]); printf "%d%.2d%.2d", $mytime[5]+1900,$mytime[4]+1,$mytime[3];' 86400)
echo $a
You could have also gotten help from the perl man pages. Check perlfunc in particular.
  #3 (permalink)  
Old 07-14-2006
rajus19 rajus19 is offline
Registered User
  
 

Join Date: Feb 2005
Location: Bangalore
Posts: 36
Thanks Blowtorch.

As a unix command its working fine, I tried to put in my perl program and made the changes to assign the previous date(format mm/dd/yyyy) to a variable but its not working fine.

Could you please look at once.

thanks,
raju
  #4 (permalink)  
Old 07-15-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
The command I gave will give the output in the yyyy/mm/dd format. You will have to switch the mytime[x] around to get the output in the format that you want.

And another thing, are you using that snippet in a perl program? Then you can use this:
Code:
@mytime=localtime (time - 86400); 
#from this point on, you can use $mytime[3] for day, $mytime[4] for month (zero based) and $mytime[5] for the year (add 1900)
  #5 (permalink)  
Old 07-18-2006
rajus19 rajus19 is offline
Registered User
  
 

Join Date: Feb 2005
Location: Bangalore
Posts: 36
Thanks blowtorch
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 03:53 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