UNIX timestamp conversion

software development

#1

I’ve been pulling dated records in Unix Timestamp format from a MySQL database with Perl for charting:
$SQLstatement = qq {Select UNIX_Timestamp(Date), Steelhead From tblProssercuryr
WHERE date > "2005-08-28"
and date < "2006-01-01"
and Steelhead IS NOT NULL
order by Date };

Setting up the chart axes uses a method (from ChartDirector 4.0) that takes the dates in the UNIX timestamp format:
$c->xAxis()->setDateScale(perlchartdir::chartTime2(1125302400), perlchartdir::chartTime2(1136102400), 7 * 86400);

I’m having trouble getting the correct timestamp calculated for the dates I need. Is there any utilities out there that help convert date to UNIX timestamp? Is there a construction that would let me embed this function right in the xAxis line?


#2

There may be an easier way, but this looks promising:
http://search.cpan.org/~pijll/DateTime-Format-Epoch-0.09/lib/DateTime/Format/Epoch.pm
(specifically, DateTime::Format::Epoch::UNIX)

It doesn’t seem to be installed, but you could request it.


#3

How about http://aspn.activestate.com/ASPN/docs/ActivePerl/5.8/lib/Time/Local.html

:cool: Perl / MySQL / HTML+CSS


#4

That seems to work. I can embed the call to timelocal right in the call to chartTime2 so I can specify that I want the x-axis to start on Aug. 29, 2005 much easier than figuring out for myself what the UNIX timestamp of that date would be, like the second chartTime2 in this line:

$c->xAxis()->setDateScale(perlchartdir::chartTime2(timelocal_nocheck 0,0,0,29,7,05), perlchartdir::chartTime2(1136102400), 7 * 86400);

See the completed chart at http://ykfp.org/ChartDirector/perldemo_cgi/dbprossersthd4.pl

Step by step, Atropos7 is making me a perl programmer. Thanks.


#5

It turns out I’m doing this the hard way, imbedding reversals inside of reversals. In the ChartDirector Perl library, the original function chartTime takes the time arguments as year, month,day, [h, n, s], while I was fixated on making the function chartTime2 work for me, when chartTime2 is the only one that takes UNIX Timestamp dates. Now I can simplify the line as:

$c->xAxis()->setDateScale(perlchartdir::chartTime(2005, 8, 28), perlchartdir::chartTime(2005, 12,31), 7 * 86400);