Perl Language Dates and Time Working with elements of datetime

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Set single element:

$dt->set( year => 2016 );

Set many elements:

$dt->set( year => 2016, 'month' => 8);

Add duration to datetime

$dt->add( hour => 1, month => 2)

Datetime subtraction:

my $dt1 = DateTime->new(
      year      => 2016,
      month     => 8,
      day       => 20,
);

my $dt2 = DateTime->new(
      year      => 2016,
      month     => 8,
      day       => 24,
);

my $duration = $dt2->subtract_datetime($dt1);
print $duration->days

You will get the result is 4 days



Got any Perl Language Question?