note
naikonta
Well, basically, just reverse the date components in the list and put it back as string.
<code>
my $in_date = '30-04-2007';
my $db_date = join '-', reverse split '-', $in_date;
# to get the original format, do the same thing
my $pr_date = join '-', reverse split '-', $db_date;
print "in: $in_date; db: $db_date; pr: $pr_date\n";
# in: 30-04-2007; db: 2007-04-30; pr: 30-04-2007
</code>
For multi-possible-separator, use the non-digit character class for <c>split()</c>.
<code>
my $in_date = '02/05/2007'; # or 02.05.2007, or any non-digit-separators
my $db_date = join '-', reverse split /\D/, $in_date;
# to get the original format, do the same thing as before
my $sep = '-';
my $pr_date = join $sep, reverse split '-', $db_date;
print "in: $in_date; db: $db_date; pr: $pr_date\n";
# in: 02/05/2007; db: 2007-05-02; pr: 02-05-2007
</code>
In this situation, there's no way to convert the date back with its original separator unless you kept it somewhere somehow, if that really matters. Besides, this might be a good chance to enforce your standard separator :-)
614222
614222