Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > dates...

Reply
Thread Tools

dates...

 
 
Sergei Shelukhin
Guest
Posts: n/a
 
      06-15-2004
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,$isd st) =
localtime($startdate);
for my $scalar ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st)
{ 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 )?



 
Reply With Quote
 
 
 
 
Gregory Toomey
Guest
Posts: n/a
 
      06-15-2004
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/Da...functions.html


gtoomey
 
Reply With Quote
 
 
 
 
Joe Smith
Guest
Posts: n/a
 
      06-16-2004
Sergei Shelukhin wrote:

> my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st) =
> 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
 
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




Advertisments