[ic] Sorting by date

interchange-users@icdevgroup.org interchange-users@icdevgroup.org
Tue Aug 27 15:30:02 2002


Quoting marc.brevoort (marc.brevoort@armazemdedados.com):
> On Tuesday 27 August 2002 18:18, you wrote:
> > ...sorting by date...
> > i could store each value numerically and sort by year then month then
> > day of the month then time but this seems an ugly way to go about it.
> 
> The yyyy-mm-dd hh:mm:ss format is ISO standard. It has some obvious benefits: 
> alpha-sortable, not likely to cause confusion to people as could happen by 
> mixing European notation dd-mm-yyyy and US notation mm-dd-yyyy... if you only 
> have the choice of storing the date as text, yyyy-mm-dd is the way to go.
> 
> Of course what you display to your users does not have to be the same as what 
> you store in the database. With a few lines of Perl code you can transform 
> yyyy-mm-dd into any notation you like. Something like the following would do
> the trick (warning:untested code ahead!)
> 
> [perl]
> 	my $date="2002-03-04";
> 	my @months=("jan","feb","mar", "apr", "may", "jun",
> 			"jul","aug","sep","oct","nov","dec");
> 	my @datear=split("-",$date);
> 	my $year=@datear[0];
> 	my $month=@datear[1];
> 	my $day=@datear[2];
> 	return @months[$month-1]." ".$day." ".$year;
> [/perl]
> 

I believe convert-date handles ISO (minus seconds, probably should fix
that).

    [convert-date format="%c"]2002-08-05 23:47:33[/convert-date]

shows:

    Mon 05 Aug 2002 11:47:00 PM EDT

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.513.523.7621      <mike@perusion.com>

Research is what I'm doing when I don't know what I'm doing.
-- Wernher Von Braun