[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
[ic] Sorting by date
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]