Skip to main content.
home | support | download

Back to List Archive

Re: How could I modify the date format output?

From: <moseley(at)>
Date: Thu Aug 14 2003 - 14:52:20 GMT
On Wed, Aug 13, 2003 at 10:36:03PM -0700, Bucharow Leonard wrote:
> How could I modify the DateRanges_time_low and DateRanges_time_high format
> in the
> (I would set the date range in format "dd-Mon-yyyy" without time, cause the
> "Select Date Range" option is without too.)

Maybe I don't understand.  Do you mean this string?:

  Results limited to dates Fri Aug 1 00:00:00 2003 to Sun Aug 31 23:59:59 2003

If so then in there's this section:

    if ( $results->{DateRanges_time_low} && $results->{DateRanges_time_high} ) {
        my $low = scalar localtime $results->{DateRanges_time_low};
        my $high = scalar localtime $results->{DateRanges_time_high};
        $limits = <<EOF;
            <td colspan=2>
                <font size="-2" face="Geneva, Arial, Helvetica, San-Serif">
                &nbsp;Results limited to dates $low to $high

Notice the "scalar localtime" -- that's just using Perl's built-in date 
formatting.  (perldod -f localtime)

There's a number of ways to format the time using various Perl modules.

For example, you can use the strftime() POSIX function.

use POSIX 'strftime';

$ perl
use POSIX 'strftime';
print strftime('%d-%b-%Y', localtime( time() ) );

So that would be:

$low  = strftime('%d-%b-%Y', localtime $results->{DateRanges_time_low} );
$high = strftime('%d-%b-%Y', localtime $results->{DateRanges_time_high} );

POSIX is a huge module, so you may want to use a different module such 
as Date::Format if you have that installed.

$ perl
use Date::Format;
print time2str('%d-%b-%Y', time());

time2str() takes just a time() number so it would be:

$low  = time2str('%d-%b-%Y', $results->{DateRanges_time_low} );

> I've found a mail in the list with related problem for properties in
> swish.cgi:
> my @props = map {
> $_ eq 'swishlastmodified' ? "$_ fmt='%Y-%m-%d'" : $_
> } @properties;
> $self->swish_command( -x => join( '\t', map { "<$_>" } @props ) . '\n' );
> Could I use this for low and high? If yes how?

Not for what you want.  The reason is that is sending a fmt string to
swish-e (using the -x swish-e option).  But the dates you want printed
are just dates within the script.  But if you want to change the format 
of the last modified dates printed on each record, yes you can do that.

Bill Moseley
Received on Thu Aug 14 14:53:34 2003