localtime - user input - output in same format

D

Dan Vesma

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,$isdst) = 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
 
S

Simon Taylor

Dan said:
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,$isdst) = 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
 
B

Brian Wakem

Thomas Nagel said:
Hi,


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top