in reply to Re: Parsing/regex question
in thread Parsing/regex question

incorporated into my code, less lines now :D

thanks for the tip!

Replies are listed 'Best First'.
Re^3: Parsing/regex question
by ikegami (Patriarch) on Jul 06, 2009 at 20:11 UTC

    Don't, it's wrong.

    86400 seconds sooner/later can be the same day.
    86400 seconds sooner/later can be two days earlier/later.

    use DateTime qw( ); my $today = DateTime->today( time_zone => 'local' ); my $tomorrow = $today->add ( days => 1 ); my $yesterday = $today->subtract( days => 1 ); print "Today is: ", $today ->strftime('%m/%d/%Y'), "\n"; print "Tomorrow is: ", $tomorrow ->strftime('%m/%d/%Y'), "\n"; print "Yesterday is: ", $yesterday->strftime('%m/%d/%Y'), "\n";

    Update: Added solution.
    Update: Fixed spelling of time_zone. (underscore was missing)

      In which case, we can use a CPAN module, such as Date::Simple:
      use Date::Simple ('date', 'today'); my $date = today(); print "Today is: " , $date, "\n"; print "Tomorrow is: " , $date + 1, "\n"; print "Yesterday is: " , $date - 1, "\n";

      Update: oops... didn't see your updated code

      cool! doing the following now:
      $today_tmp = DateTime->now(); $tomorrow_tmp = DateTime->now()->add( days => 1 ); $yesterday_tmp = DateTime->now()->subtract( days => 1 ); $today = $today_tmp->mdy('/'); $tomorrow = $tomorrow_tmp->mdy('/'); $yesterday = $yesterday_tmp->mdy('/'); print "Today: $today -=- "; print "Tomorrow: $tomorrow -=- "; print "Yesterday: $yesterday -=- ";

      Works perfectly!

        No, it doesn't. I thought you wanted the local date, not the date halfway around the world. If so, you introduced a bug by removing time_zone => 'local'. (Yeah, I had it misspelled.)

        I'm also curious as to why you changed from today to now.