Problem: Date fields in Access are returned as dd/mm/yyyy hh:mi:ss and printed as such on my HTML output. Reasons for problem: I have a generic function that parses db output and converts into an arrayref that is passed as arguments to the TMPL_LOOP attribute of HTML::Template. This function does not know about the data types it receives. The way the SELECT query is framed takes care that I dont have to do individual field assignments to map attributes in the template to the SELECTed fields. Code attached:
sub get_tmpl_loop_arrayref_bind #Given an SQL query this will return an arrayref compatible with TMPL_ +LOOP. Works where the query does not contain a , before the 'from' an +d where there is no subquery. { my ($dbh, $sql, @binds, $sessID) = @_; $dbh->{RaiseError}=0; $dbh->{PrintError}=0; $sql=~/select\s+(.*?)from\s+.*/ig; my $onlyfields = $1; my @fields = split /,/, $onlyfields; foreach my $field (@fields) { $field=$1 if ($field=~/.*?\s+as\s+\[(.*)\]/ig); #Fields taken with the + as identifier are parsed here. Eg. "select a/b as ratio" $field=~s/\s+//ig; } my $sth = $dbh->prepare($sql) || die "Could not prepare query $sql in +get_tmpl_loop_arrayref"; $sth->execute || die "Could not execute query $sql in get_tmpl_loop_ar +rayref"; my @loop_data = (); while (my $hash_op = $sth->fetchrow_hashref('NAME_lc')) { my %row_data; foreach my $field (@fields) { $row_data{$field}=$hash_op->{$field}? $hash_op->{$fiel +d}:'-' ; } $row_data{id}=$sessID if $sessID; push (@loop_data, \%row_data); } if ($dbh->errstr()) { return $dbh->errstr(); } else {return \@loop_data;} }
The SELECT statement would be as follows:
"SELECT username, name, role, email, phone, mobile, creation_date from + user where creator='".$session->param('username')."'";
and the HTML:Template would be like so:
<TMPL_LOOP NAME=all_users> <!-- Data display --> <TR> <TD WIDTH="25%" class="tblvlu"><TMPL_VAR NAME=username></TD> <TD WIDTH="25%" class="tblvlu"><TMPL_VAR NAME=name></TD> <TD WIDTH="25%" class="tblvlu"><TMPL_VAR NAME=role></TD> <TD WIDTH="25%" class="tblvlu"><TMPL_VAR NAME=email></TD> <TD WIDTH="25%" class="tblvlu"><TMPL_VAR NAME=phone></TD> <TD WIDTH="25%" class="tblvlu"><TMPL_VAR NAME=mobile></TD> <TD WIDTH="25%" class="tblvlu"><TMPL_VAR NAME=creation_date></TD>

Works like a charm except the display of the creation date which is usually something like
10/06/2005 00:00:00
Regards,
Rajesh
PS: Was that too much detail??

In reply to Handling MS-Access date time by k_rajesh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.