Gossamer Forum
Home : Products : DBMan : Customization :

correct date format or how to change date format

Quote Reply
correct date format or how to change date format
Hi there,

Until now i haven't use the date field inside my database file. The database file isn't generate by dbman but exporting from a offline database to the dbman format.

inside this database i use the format dd/mm/yyyy "only digits" can DBman use this date format? or do i have to make changes to the script?

it's for the addon routine of JPdeni:whatsnew

Thanks

Marcel
Quote Reply
Re: correct date format or how to change date format In reply to
Edit the sub get_date_and_time in db.cgi.

Code:
sub get_date_and_time {
# --------------------------------------------------------
# Gets date and time when the database was last modified.

my ($time) = @_;
($time) | | ($time = time());
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");
($hour > 11) ? ($am_pm = "pm") : ($am_pm = "am");
if ($hour > 12) { $hour -= 12; }
elsif ($hour < 1) {$hour = 12; }
return "$day/$months[$mon]/$year";
}

That should do it...I think.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited September 02, 1999).]

[This message has been edited by Eliot (edited September 02, 1999).]
Quote Reply
Re: correct date format or how to change date format In reply to
Yep. You'll have to change both sub get_date and sub date_to_unix.

Code:
sub get_date {
# --------------------------------------------------------
# Returns the date in the format "dd/mm/yyyy".

my ($time1) = $_[0];
($time1) or ($time1 = time());

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time1);

($day < 10) and ($day = "0$day");
++$mon;
($mon < 10) and ($mon = "0$mon");
$year = $year + 1900;

return "$day/$mon/$year";
}

sub date_to_unix {
# --------------------------------------------------------
# This routine must take your date format and return the time a la UNIX time().
# Some things to be careful about..
# int your values just in case to remove spaces, etc.
# catch the fatal error timelocal will generate if you have a bad date..
# don't forget that the month is indexed from 0!
#
my ($date) = $_[0];
my ($time);
my ($day, $mon, $year) = split(/\//, $_[0]);
unless ($day and $mon and $year) { return undef; }

use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900;
$mon = int($mon) - 1;
$time = timelocal(0,0,0,$day,$mon,$year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}

Let me know if you have any problems with the "What's New" mod.

------------------
JPD





Quote Reply
Re: correct date format or how to change date format In reply to
Thanks for your fast reply i will go and try it out. If neccesary i get back to you

Greetings
Marcel