Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Time Question

30 views
Skip to first unread message

E.D.G.

unread,
Aug 1, 2012, 12:16:24 PM8/1/12
to
TIME QUESTION

The latest version of ActiveState Perl is being used on one computer. And
ActiveState 5.10 is being used on another as it needs to have a large number
of special modules running.

Question: Is there a Perl routine in either of those versions or some
module that will let you work with dates as if they were numbers?

The goal is to be able to tell what the UTC date and time are (ex.
2012/08/01 12:34:56) that is say 130 days and 4 hours ahead of some date
such as today or 30 days from now.

Wolf Behrenhoff

unread,
Aug 1, 2012, 12:34:58 PM8/1/12
to
Am 01.08.2012 18:16, schrieb E.D.G.:
> TIME QUESTION
>
> The goal is to be able to tell what the UTC date and time are (ex.
> 2012/08/01 12:34:56) that is say 130 days and 4 hours ahead of some date
> such as today or 30 days from now.

perldoc Date::Calc

- Wolf


Ben Morrow

unread,
Aug 1, 2012, 3:44:01 PM8/1/12
to

Quoth Wolf Behrenhoff <NoSpamPleaseB...@gmx.net>:
IMHO it's better to just go with DateTime. While there are other modules
which are smaller and (in principle) faster, I don't believe any of them
Do Everything Right the way DateTime does. Having to convert your code
from one API to another when you find you've hit a case your chosen
module doesn't handle properly is probably worth avoiding.

Ben

E.D.G.

unread,
Aug 3, 2012, 7:38:01 AM8/3/12
to
"Wolf Behrenhoff" <NoSpamPleaseB...@gmx.net> wrote in message
news:50195ab3$0$6555$9b4e...@newsspool4.arcor-online.net...

> perldoc Date::Calc

Thanks for the reference.

E.D.G.

unread,
Aug 3, 2012, 7:50:45 AM8/3/12
to
"Ben Morrow" <b...@morrow.me.uk> wrote in message
news:1hdoe9-...@anubis.morrow.me.uk...
>
> IMHO it's better to just go with DateTime.

Thanks for the information.

I myself just created two Perl subroutines from some True Basic code
that will also do this. The first translates dates into a single number
that can be added to other numbers that have that format. And the final
number can then be decoded back to year and month etc. by the second
subroutine. Together they represent about 50 lines of code.

I am planning to try to post that code to this Newsgroup after the
subroutines have been running for a while and they look like they are not
making any mistakes. However, I learned how to program years ago using
Fortran and Basic. So, the code will probably not look very attractive to
Perl programmers. People can make any adjustments they wish to the code
before using it.

However, if those Perl routines people mentioned are easier to use
then I am planning to use them instead for my own applications.

HASM

unread,
Aug 3, 2012, 12:22:20 PM8/3/12
to
Wolf Behrenhoff <NoSpamPleaseB...@gmx.net> writes:

>> The goal is to be able to tell what the UTC date and time are (ex.
>> 2012/08/01 12:34:56) that is say 130 days and 4 hours ahead of some date
>> such as today or 30 days from now.

> perldoc Date::Calc

or Date::Manip

-- HASM

charley%pu...@gtempaccount.com

unread,
Aug 3, 2012, 1:20:26 PM8/3/12
to
On Friday, August 3, 2012 7:50:45 AM UTC-4, E.D.G. wrote:
> "Ben Morrow" <ben<at>morrow.me.uk> wrote in message
>
> news:1hdoe9-u151.ln1<at>anubis.morrow.me.uk...
Here is a snippit using DateTime

use DateTime;

my $now = DateTime->now;
my $future = $now->clone->add(days => 130, hours => 4);
print $now, "\n";
print $future, "\n";

Chris

Mark Kramer

unread,
Aug 3, 2012, 5:35:15 PM8/3/12
to
In article <JsednYi0XZ8Oy4TN...@earthlink.com>,
E.D.G. <edgr...@ix.netcom.com> wrote:
>The goal is to be able to tell what the UTC date and time are (ex.
>2012/08/01 12:34:56) that is say 130 days and 4 hours ahead of some date
>such as today or 30 days from now.

You mean like:

$now = time;
$before = $now - 130*86440 - 4*60;
print "now is " . scalar(gmtime($now)) . "\n";
print "then was " . scalar(gmtime($before)) . "\n";
$later = $now + 30* 86440;
print "later will be " . scalar(gmtime($later)) . "\n";


Mark Kramer

unread,
Aug 3, 2012, 5:38:27 PM8/3/12
to
In article <5IOdnYioVt2SJobN...@earthlink.com>,
E.D.G. <edgr...@ix.netcom.com> wrote:
> I myself just created two Perl subroutines from some True Basic code
>that will also do this. The first translates dates into a single number
>that can be added to other numbers that have that format.

Like timelocal and timegm?

require "timelocal.pl";

>And the final
>number can then be decoded back to year and month etc. by the second
>subroutine. Together they represent about 50 lines of code.

Like localtime and gmtime?

Mark Kramer

unread,
Aug 3, 2012, 5:41:05 PM8/3/12
to
In article <jvhg6j$j3k$1...@pcls6.std.com>,
Mark Kramer <c28...@TheWorld.com> wrote:
>$before = $now - 130*86440 - 4*60;

Make that:

$before = $now - 130*24*60*60 - 4*60*60;

E.D.G.

unread,
Aug 8, 2012, 8:13:24 PM8/8/12
to
"E.D.G." <edgr...@ix.netcom.com> wrote in message
news:JsednYi0XZ8Oy4TN...@earthlink.com...
> TIME QUESTION

I have seen all of the postings for this question and the other thread
regarding the Perl Newsgroup. And I have done some reading on Date Calc.
There are several projects that I am trying to finish that have deadlines
associated with them. And it will probably be a while before I will have a
chance to comment on any of the other recent posts.

0 new messages