C'è un modo per capire il primo giorno del mese (giorno min) e l'ultimo giorno di un mese (giorno max), dato il mese come input, usando DateTime
in perl?Come posso ottenere il primo e l'ultimo giorno del mese con Perl's DateTime?
Finora, ho capito come passare un primo appuntamento, l'ultimo giorno per darmi una serie di giorni.
Ma quello che voglio fare ora è passare un mese come argomento, diciamo 201203
e restituire min, maxday.
È possibile con DateTime?
Inoltre, desidero modificare la maschera del formato della data da AAAAMMGG a AAAA-MM-GG.
use strict;
use warnings;
use DateTime;
unless(@ARGV==2)
{
print "Usage: myperlscript first_date last_date\n";
exit(1);
}
my ($first_date,$last_date)[email protected];
my $date=DateTime->new(
{
year=>substr($first_date,0,4),
month=>substr($first_date,4,2),
day=>substr($first_date,6,2)
});
while($date->ymd('') le $last_date)
{
print $date->ymd('') . "\n";
#$date->add(days=>1); #every day
$date->add(days=>30);
}
Risultati attesi:
2012-03-01
2012-03-31
Il giorno minimo è sempre 1! – theglauber