Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > localtime - user input - output in same format

Reply
Thread Tools

localtime - user input - output in same format

 
 
Dan Vesma
Guest
Posts: n/a
 
      10-07-2004
Good morning,

I am trying to get to grips with a timesheet app. I am presenting the
user with a form to enter details of an undertaken task, including the
date on which the work was undertaken. I am using

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st) = localtime
time;

to populate an HTML form with today's day/month/year. The user can
then change this figure if the work was done the previous day, or a
month ago, or whenever.

When that form is returned, I would ideally like to store a single
number to represent the day that the work was undertaken, so that I
can sort tasks by the date undertaken. How do I get from a day, a
month and a year to the number of seconds since 1.1.1970?

Any clues?

Thanks,


Daniel V
 
Reply With Quote
 
 
 
 
Simon Taylor
Guest
Posts: n/a
 
      10-07-2004
Dan Vesma wrote:
> Good morning,
>
> I am trying to get to grips with a timesheet app. I am presenting the
> user with a form to enter details of an undertaken task, including the
> date on which the work was undertaken. I am using
>
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st) = localtime
> time;
>
> to populate an HTML form with today's day/month/year. The user can
> then change this figure if the work was done the previous day, or a
> month ago, or whenever.
>
> When that form is returned, I would ideally like to store a single
> number to represent the day that the work was undertaken, so that I
> can sort tasks by the date undertaken. How do I get from a day, a
> month and a year to the number of seconds since 1.1.1970?
>
> Any clues?



See the FAQ entry:

perldoc -q seconds

and more specifically:

use Date::Calc qw(Date_to_Time);

....

my $time = Date_to_Time($year,$month,$day,
$hour,$min,$sec);

print "time: $time\n";


Regards,

Simon Taylor
 
Reply With Quote
 
 
 
 
Brian Wakem
Guest
Posts: n/a
 
      10-07-2004

"Thomas Nagel" <(E-Mail Removed)> wrote in message
news:ck2tav$d6p$(E-Mail Removed)...
> Hi,
>
> > When that form is returned, I would ideally like to store a single
> > number to represent the day that the work was undertaken, so that I
> > can sort tasks by the date undertaken. How do I get from a day, a
> > month and a year to the number of seconds since 1.1.1970?

>
> use Time::Local;
> my $seconds = timelocal(0, 0, 0, $day, $month - 1, $yyyy);
>
> $day is in range 1..31 while $month is in (0..11).
>


$month must be 1..12 here as you are supplying $month - 1 to the function,
but not actually changing $month. If $month eq 0 then you'd be passing -1
to the function.

--
Brian Wakem


 
Reply With Quote
 
 
 
Reply

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
time.localtime() Format Question OleMacGeezer Python 1 08-20-2006 05:53 PM
Keep Unix Timestamp format with Localtime function triwolf Perl Misc 2 02-06-2006 01:14 AM
Converting for localtime() or gmtime() to time() Stephen Perl 1 05-19-2004 03:51 PM
The output for localtime() is not correct. david C Programming 3 08-27-2003 08:04 AM
java input and output stream to the same file at the same time? Krick Java 1 08-15-2003 05:55 PM



Advertisments