Velocity Reviews > Perl > DateTime.pm and midnight

# DateTime.pm and midnight

Arvin Portlock
Guest
Posts: n/a

 12-29-2005
Why does the following code return 0 minutes instead of 60?

use DateTime;
use DateTime:uration;

my \$year = 1969;
my \$month = 4;
my \$day = 2;
my \$hour = 23;

my \$datetime = new DateTime (year => \$year,
month => \$month,
day => \$day,
hour => \$hour);

my \$onehour = new DateTime:uration (hours => '1');

my \$elevenpm = new DateTime (year => \$year,
month => \$month,
day => \$day,
hour => '23');

my \$midnight = \$elevenpm + \$onehour;

my \$delta = \$midnight - \$datetime;
print \$delta->minutes, "\n";

J. Gleixner
Guest
Posts: n/a

 12-30-2005
Arvin Portlock wrote:
> Why does the following code return 0 minutes instead of 60?
>
> use DateTime;
> use DateTime:uration;
>
> my \$year = 1969;
> my \$month = 4;
> my \$day = 2;
> my \$hour = 23;
>
> my \$datetime = new DateTime (year => \$year,
> month => \$month,
> day => \$day,
> hour => \$hour);
>
> my \$onehour = new DateTime:uration (hours => '1');
>
> my \$elevenpm = new DateTime (year => \$year,
> month => \$month,
> day => \$day,
> hour => '23');
>
> my \$midnight = \$elevenpm + \$onehour;
>
> my \$delta = \$midnight - \$datetime;
> print \$delta->minutes, "\n";

Because it's 1 hour and 0 minutes difference. Minutes are 0-59.

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Ethan Furman Python 6 02-22-2009 09:20 PM Jordan Richard ASP .Net 2 04-30-2005 08:35 PM meanoldman MCSE 0 02-28-2005 05:55 PM karlpov DVD Video 8 08-22-2004 02:05 PM ecconando@hotmail.com DVD Video 1 08-16-2003 10:49 PM

Advertisments