dates...

Discussion in 'Perl Misc' started by Sergei Shelukhin, Jun 15, 2004.

  1. I have mysql database with datetime column PDT in the table Record. I run
    the following:

    my ($startdate) = $db->selectrow_array("SELECT MIN(PDT) FROM Record");
    print "$startdate"; # prints out datetime ~half a hour ago from this message
    post ;)
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
    localtime($startdate);
    for my $scalar ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
    { print "$scalar<br />"; }

    #prints out:
    24
    33
    21
    31
    11
    69
    3
    364
    0


    The date is ok; the values are obviously not.

    What's wrong with that?
    Is the date returned from selectrow statement really just a string? And if
    yes, what's its workaround ( e.g. is it in the same format everywhere, on
    all servers and what do I do if it is not ;) )?
     
    Sergei Shelukhin, Jun 15, 2004
    #1
    1. Advertising

  2. Sergei Shelukhin wrote:

    > I have mysql database with datetime column PDT in the table Record. I run
    > the following:
    >
    > my ($startdate) = $db->selectrow_array("SELECT MIN(PDT) FROM Record");


    You dont expoicitly state what format you want; it will go to some
    default ...
    > localtime($startdate);

    .... which to use to call localtime

    Try using explicit formats
    select date_format(min(pdt),"%e-%b-%Y %l:%i:%s %p") from record

    or

    select date_format(min(pdt),"%e") myday,
    date_format(min(pdt),"%d") mymon,
    ....
    from record

    See http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html


    gtoomey
     
    Gregory Toomey, Jun 15, 2004
    #2
    1. Advertising

  3. Sergei Shelukhin

    Joe Smith Guest

    Sergei Shelukhin wrote:

    > my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
    > localtime($startdate);
    > 24 > 33 > 21 > 31 > 11 > 69 > 3 > 364 > 0


    The argument to localtime() is expected to be a positive integer.

    print scalar localtime(0); # "Wed Dec 31 16:00:00 1969" for US/Pacific
    print scalar localtime(1087379540);# "Wed Jun 16 02:52:20 2004" PDT
    print scalar localtime(2004); # "Wed Dec 31 16:33:24 1969" for PST
    print scalar localtime("2004-06-16 02:52:20"); # same as localtime(2004)

    It appears that your timezone is 5 hours east of US/Pacific and that you gave
    localtime() a string that had "2004" before the first non-digit character.
    -Joe
     
    Joe Smith, Jun 16, 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. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    911
    Rob Schieber
    Sep 30, 2005
  2. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    235
    Mark Schupp
    Aug 9, 2004
  3. Replies:
    1
    Views:
    240
    Jano Svitok
    Jul 17, 2007
  4. kellygreer1

    RFC-822 dates into Ruby dates

    kellygreer1, Jun 8, 2008, in forum: Ruby
    Replies:
    1
    Views:
    266
    Eric I.
    Jun 8, 2008
  5. Dr J R Stockton

    FAQ Dates; Opera Dates.

    Dr J R Stockton, Jun 18, 2007, in forum: Javascript
    Replies:
    0
    Views:
    191
    Dr J R Stockton
    Jun 18, 2007
Loading...

Share This Page