Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-02-2009
Registered User
 

Join Date: Oct 2009
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Date in Solaris

Hi,

I am working on date operations in perl. using following code, I am getting today date as per my required format.


Code:
my $date1 = `date '+%m/%d/%Y'`;

can I find day+1 date. (ie. If today is 12/01/2009 then I want to edit above code t find 12/02/2009)

---------- Post updated 12-02-09 at 01:58 AM ---------- Previous update was 12-01-09 at 08:28 PM ----------

can anyone please advice
Sponsored Links
    #2  
Old 12-02-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Cat herder
 

Join Date: Dec 2008
Location: Vienna, Austria, Earth
Posts: 5,486
Thanks: 38
Thanked 324 Times in 301 Posts
Why do you call an external program for something that Perl can do fine by itself?
Code:
$ cat time.pl
#!/usr/bin/perl

use strict;
use warnings;

my $time     = time;
my @today    = localtime($time);
my @tomorrow = localtime( $time + 24 * 60 * 60 );

printf "   Today: %02d/%02d/%04d\n", $today[4] + 1, $today[3], $today[5] + 1900;
printf "Tommorow: %02d/%02d/%04d\n", $tomorrow[4] + 1, $tomorrow[3],
  $tomorrow[5] + 1900;
$ perl time.pl
   Today: 12/02/2009
Tommorow: 12/03/2009

See the Perl documentation for time, localtime, and gmtime for more information.

Last edited by pludi; 12-02-2009 at 05:36 AM.. Reason: corrected code
Sponsored Links
    #3  
Old 12-02-2009
Registered User
 

Join Date: Oct 2009
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Will it give me 12/01/2009 after 11/30/2009. It shouldnt be 11/31/2009.

Also how to take it in a variable?

Last edited by gentleDean; 12-02-2009 at 04:30 AM.. Reason: Asked one more question
    #4  
Old 12-02-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Cat herder
 

Join Date: Dec 2008
Location: Vienna, Austria, Earth
Posts: 5,486
Thanks: 38
Thanked 324 Times in 301 Posts
  1. Try it. In the above example, change the line
    Code:
    my $time     = time;

to

Code:
my $time     = 1259578800; # 2009-11-30 12:00:00 PM

and run it again.
  • perldoc -f sprintf
  • We won't do all the work for you, you know.
    Sponsored Links
    Closed Thread

    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes

    More UNIX and Linux Forum Topics You Might Find Helpful
    Thread Thread Starter Forum Replies Last Post
    date -d compatibility on Solaris pavanlimo Shell Programming and Scripting 3 04-03-2009 02:06 AM
    date -d nightmare on Solaris pavanlimo Solaris 1 04-02-2009 11:34 AM
    Find solaris os installation date vadivukumar Solaris 6 10-08-2008 11:57 AM
    change system date in solaris murad.jaber Solaris 10 03-24-2008 03:12 AM
    Install Date of Solaris Machine smoothstylez UNIX for Dummies Questions & Answers 2 07-08-2005 12:15 PM



    All times are GMT -4. The time now is 12:47 AM.