time format conversion

time format conversion

am 21.04.2011 11:37:05 von cc

Hi,

I have two strings that shows different times and I
want to find the difference in # of hours.

In PHP, there's strtotime(), but there isn't one
in Perl that I can find.

The string format is: mm/dd/yyyy hh:mm:ss

So if t1 and t2 are of the aforementioned format,
I just do a t2 - t1 and it should give me
the # of hours between the two datetimes.

Is there a function that can do this?

Thanks

Ed


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: time format conversion

am 21.04.2011 11:52:42 von Shawn Wilson

--001517473586ce030104a16ab318
Content-Type: text/plain; charset=ISO-8859-1

On Apr 21, 2011 5:38 AM, "cc" wrote:
>
> Hi,
>
> I have two strings that shows different times and I
> want to find the difference in # of hours.
>
DateTime?
search.cpan.org/~drolsky/DateTime-0.66/lib/DateTime.pm

> In PHP, there's strtotime(), but there isn't one
> in Perl that I can find.
>
Why would I want to bloated my core to mess with dates when half of what I
do doesn't need that functionality?

> The string format is: mm/dd/yyyy hh:mm:ss
>
If its always in that format, just split and define a hash and pass it to
dt. Otherwise, use dt:format:natural.

> So if t1 and t2 are of the aforementioned format,
> I just do a t2 - t1 and it should give me
> the # of hours between the two datetimes.
>
As stated in the doc, dt overloads the variables so that you can do that
easy enough.

> Is there a function that can do this?
>
I don't think there is much to do with time and dates that dt (or other
modules under that namespace) can't handle.

--001517473586ce030104a16ab318--

Re: time format conversion

am 21.04.2011 18:16:52 von Karl Kaufman

Alternatives to shawn's response (w/o commenting on relative benefits)...

----- Original Message -----
From: "cc"
To:
Sent: Thursday, April 21, 2011 4:37 AM
Subject: time format conversion


> Hi,
>
> I have two strings that shows different times and I
> want to find the difference in # of hours.
>
> In PHP, there's strtotime(), but there isn't one
> in Perl that I can find.

If loading additional modules is an option, the following can be of use...

Date::Manip
http://search.cpan.org/~sbeck/Date-Manip-6.23/lib/Date/Manip .pod
Date::Calc
http://search.cpan.org/~stbey/Date-Calc-6.3/lib/Date/Calc.po d

see also: The Many Dates and Times of Perl
http://www.perl.com/pub/2003/03/13/datetime.html




--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: time format conversion

am 21.04.2011 18:53:15 von Shawn Wilson

--0016e6dd8f3ddbd78704a17093a5
Content-Type: text/plain; charset=ISO-8859-1

On Apr 21, 2011 12:17 PM, "Karl Kaufman" wrote:
>
> Alternatives to shawn's response (w/o commenting on relative benefits)...

You won't mention the benefits, but I will... :)
>
> ----- Original Message ----- From: "cc"
> To:
> Sent: Thursday, April 21, 2011 4:37 AM
> Subject: time format conversion
>
>> Hi,
>>
>> I have two strings that shows different times and I
>> want to find the difference in # of hours.
>>
>> In PHP, there's strtotime(), but there isn't one
>> in Perl that I can find.
>

Now that we've gotten into this, why do you only have one way to manipulate
dates in php? Isn't that sorta limiting?

>
> If loading additional modules is an option, the following can be of use...
>

If he's using perl and can't install modules on the destination computer, he
might want to consider par before anything else.

> Date::Manip
> http://search.cpan.org/~sbeck/Date-Manip-6.23/lib/Date/Manip .pod
> Date::Calc
> http://search.cpan.org/~stbey/Date-Calc-6.3/lib/Date/Calc.po d
>

d:manip is cool. I started out using it. But then I found it too limiting.
This is explained in the three paragraphs from the below link I've pasted
for reference.

> see also: The Many Dates and Times of Perl
> http://www.perl.com/pub/2003/03/13/datetime.html
>

But I want convenience. If I'm dealing with many datetimes and I need to
parse various inputs, generate different formats, and do lots of
calculations, then a convenient and uniform API can go a long way towards
code maintainability. The extra glue code needed to make different modules
cooperate can quickly obscure the actual intent of the program.

Efforts in the past to herd all the existing module authors towards a common
API have failed, so rather than try that again, I decided to just write even
more datetime code. As we all know, the best way to put out a fire is to
pour copious amounts of gasoline on it. In order to make my project sound
cool, I'm calling it the "Perl DateTime Suite", which sounds much better
than "more date and time modules".

The goal for this project is to produce a suite of datetime modules that do
everything you'd ever need related to dates and times. The modules in this
suite will cooperate with each other, which means that a module that parses
datetimes will return a standard object, and a module for formatting
datetimes will accept that standard object.

--0016e6dd8f3ddbd78704a17093a5--

Re: time format conversion

am 21.04.2011 20:14:23 von Rob Dixon

On 21/04/2011 10:52, shawn wilson wrote:
> On Apr 21/04/2011 5:38 cc wrote:
>>
>> In PHP, there's strtotime(), but there isn't one in Perl that I can
>> find.
>
> Why would I want to bloated my core to mess with dates when half of
> what I do doesn't need that functionality?

Because the 'bloat' is very tiny, and most Perl implementations won't
load unneccessary inbuilt calls.

>> The string format is: mm/dd/yyyy hh:mm:ss

Most of the world observes dd/mm/yyyy. There is no reason to assume
otherwise unless you have a solely US distribution. Even then you must
worry more about units of length, volume and money.

> If its always in that format, just split and define a hash and pass
> it to dt. Otherwise, use dt:format:natural.

I don't understand why you are abbreviating package names when even the
capitalisation is so critical to the proper functioning of the program.

You mean:

DateTime::Format::Natural

>> So if t1 and t2 are of the aforementioned format, I just do a t2 -
>> t1 and it should give me the # of hours between the two datetimes.
>>
> As stated in the doc, dt overloads the variables so that you can do
> that easy enough.

DateTime overloads the operators, not the variables.

>> Is there a function that can do this?
>
> I don't think there is much to do with time and dates that dt (or
> other modules under that namespace) can't handle.

I agree. DateTime is probably the answer, but I think you are misleading
people by referring to

> dt (or other modules under that namespace)

which makes no sense at all.

Rob


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: time format conversion

am 21.04.2011 20:33:54 von Karl Kaufman

----- Original Message -----
From: "Rob Dixon"
To:
Cc: "shawn wilson"
Sent: Thursday, April 21, 2011 1:14 PM
Subject: Re: time format conversion


> On 21/04/2011 10:52, shawn wilson wrote:
>>
>> If its always in that format, just split and define a hash and pass
>> it to dt. Otherwise, use dt:format:natural.
>
> I don't understand why you are abbreviating package names when even the
> capitalisation is so critical to the proper functioning of the program.
>
> You mean:
>
> DateTime::Format::Natural

Further, I would think that being specific, rather than using shorthand
which assumes experience/knowledge, would conform better to the mailing
list's stated audience.


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/