dates...

S

Sergei Shelukhin

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 ;) )?
 
G

Gregory Toomey

Sergei said:
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
 
J

Joe Smith

Sergei said:
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
 

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

Similar Threads

localtime(time()) 16
time format +1 hour 15
Date Problem 6
localtime and mktime 2
TimeDate conversion to string. 8
tape rotations and tape autoloaders 9
Returned wrong Year 2
eval problem! 8

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top