How do I calculate the number of days left in the month?

The best I could do was something like this, which doesn't really work:

my $now                 = DateTime->now();
my $first_of_this_month = DateTime->new(
   month   => $now->month(),
   day     => 1,
   year    => $now->year(),
);

my $one_month = DateTime::Duration->new( months => 1 );
my $one_day   = DateTime::Duration->new( days   => 1 );
my $last_day_of_this_month = $first_of_this_month + $one_month - $one_day;

my $d = DateTime::Format::Duration->new( pattern => '%e days left in
this month' );
print $d->format_duration( $now - $last_day_of_this_month ), "\n";


Thanks,
Jay

Reply via email to