Unix Date Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ndoggy020
    New Member
    • Sep 2006
    • 11

    Unix Date Help

    Hey guys.

    I need to manipulate the system date to move forward a day. So, if the system date was 02/14/08, I need the 'new' date to be 02/15/08 so my script will look for the date of 02/15/08. The thing is the file I will be looking for always has the date of the next day. Any simple unix command solution?

    Any ideas,

    Thanks
  • WinblowsME
    New Member
    • Jan 2008
    • 58

    #2
    Here's a Perl solution if you can't find anything simpler. You'll need to download the Time::Piece and Time::Seconds modules from CPAN.

    [CODE=perl]use warnings;
    use strict;
    use Time::Piece;
    use Time::Seconds;

    &init;

    sub init
    {
    my $today = localtime();
    my $days_ahead = 1;
    my $date = &get_days_ah ead ( $today, $days_ahead );

    print "$date\n";
    }

    sub get_days_ahead
    {
    my ( $date, $days ) = @_;

    for ( my $i = 0; $i < $days; $i++ )
    {
    $date += ONE_DAY;
    }

    return ( &get_mmddyy ( $date ) );
    }

    sub get_mmddyy
    {
    my ( $date ) = @_;
    my ( $weekday, $month, $day, $time, $year ) = split ( / +/, uc ( $date ) );

    if ( $month eq "JAN" ) { $month = "01"; }
    elsif ( $month eq "FEB" ) { $month = "02"; }
    elsif ( $month eq "MAR" ) { $month = "03"; }
    elsif ( $month eq "APR" ) { $month = "04"; }
    elsif ( $month eq "MAY" ) { $month = "05"; }
    elsif ( $month eq "JUN" ) { $month = "06"; }
    elsif ( $month eq "JUL" ) { $month = "07"; }
    elsif ( $month eq "AUG" ) { $month = "08"; }
    elsif ( $month eq "SEP" ) { $month = "09"; }
    elsif ( $month eq "OCT" ) { $month = "10"; }
    elsif ( $month eq "NOV" ) { $month = "11"; }
    elsif ( $month eq "DEC" ) { $month = "12"; }

    if ( length ( $day ) == 1 ) { $day = "0" . $day; }
    $year = substr ( $year, 2 );

    return ( "$month/$day/$year" );
    }[/CODE]

    Comment

    • ghostdog74
      Recognized Expert Contributor
      • Apr 2006
      • 511

      #3
      Originally posted by ndoggy020
      Hey guys.

      I need to manipulate the system date to move forward a day. So, if the system date was 02/14/08, I need the 'new' date to be 02/15/08 so my script will look for the date of 02/15/08. The thing is the file I will be looking for always has the date of the next day. Any simple unix command solution?

      Any ideas,

      Thanks
      if you have GNU date
      Code:
      # date +%Y/%m/%d -d "1 day"
      2008/02/16

      Comment

      Working...