localtime - user input - output in same format

Discussion in 'Perl Misc' started by Dan Vesma, Oct 7, 2004.

  1. Dan Vesma

    Dan Vesma Guest

    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
     
    Dan Vesma, Oct 7, 2004
    #1
    1. Advertising

  2. Dan Vesma

    Simon Taylor Guest

    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,$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
     
    Simon Taylor, Oct 7, 2004
    #2
    1. Advertising

  3. Dan Vesma

    Brian Wakem Guest

    "Thomas Nagel" <> wrote in message
    news:ck2tav$d6p$...
    > 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
     
    Brian Wakem, Oct 7, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephen
    Replies:
    1
    Views:
    1,240
    Purl Gurl
    May 19, 2004
  2. Krick
    Replies:
    1
    Views:
    1,509
    John C. Bollinger
    Aug 15, 2003
  3. david
    Replies:
    3
    Views:
    358
    Villy Kruse
    Aug 27, 2003
  4. OleMacGeezer

    time.localtime() Format Question

    OleMacGeezer, Aug 20, 2006, in forum: Python
    Replies:
    1
    Views:
    480
    Greg Krohn
    Aug 20, 2006
  5. triwolf
    Replies:
    2
    Views:
    243
    Joe Smith
    Feb 6, 2006
Loading...

Share This Page