Gossamer Forum
Home : Products : DBMan : Installation :

Problem with Date Format

(Page 1 of 2)
> >
Quote Reply
Problem with Date Format
Carol,

I have searched and searched for a Thread that solves the date format problem...to no avail. I apologize for this be being a redundant posting...if there is a Thread that explicitly solves the logging date format, please direct me to that Thread! Smile

Anyway, I installed the "What's New" date routines for both get_date and date_to_unix from your mod.html page, Carol.

I am still getting that annoying 31 Dec 1969 date format. Any ideas about how to solve this? I have this problem both on my NT and UNIX servers.

Thanks.

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
Quote Reply
Re: Problem with Date Format In reply to
I made a suggestion about it in some thread just the other day and didn't see a response as to whether it worked or not. Did you see that suggestion?


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





Quote Reply
Re: Problem with Date Format In reply to
look at the end of http://www.gossamer-threads.com/scripts/forum/resources/Forum5/HTML/001278.html ,maybe any suggestions??

-----
Mart.
Quote Reply
Re: Problem with Date Format In reply to
I am sorry that I wasn't more explicit. Smile
It is not in the actual What's New Statements that I am having a problem, but in the log files for DBMAN that the annoying date is showing up.

Sorry about that.

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
Quote Reply
Re: Problem with Date Format In reply to
Thats what bothers me also, so I've made that 'get_date2' sub in the script, and refer in the 'auth.pl' to that sub. Its not the way to 'trick' the script, so maybe there is a more 'prof' solution???
Quote Reply
Re: Problem with Date Format In reply to
Mart,

I copied unix_date sub routine and made a new routine known as log_date, then I replaced get_date with log_date in the auth.pl file. The result: NO date in the log file.

So, I changed it back to get_date...still getting that annoying date. UGH!

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
Quote Reply
Re: Problem with Date Format In reply to
No, you simply put another sub in the .cgi file, I've placed it below the original, so you have two subs:
Code:
sub get_date {
# --------------------------------------------------------
# Returns the date in the format "dd-mmm-yy".
# Warning: If you change the default format, you must also modify the &date_to_unix
# subroutine below which converts your date format into a unix time in seconds for sorting
# purposes.

$time = @_[0];
($time) | | ($time = time());

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);
my (@months) = qw!Jan Feb Mrt Apr Mei Jun Jul Aug Sep Okt Nov Dec!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;

return "$day-$months[$mon]-$year";
}

sub get_date2 {
# --------------------------------------------------------
# Returns the date in the format "dd-mmm-yy".
# Warning: If you change the default format, you must also modify the &date_to_unix
# subroutine below which converts your date format into a unix time in seconds for sorting
# purposes.

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(time());
my (@months) = qw!Jan Feb Mrt Apr Mei Jun Jul Aug Sep Okt Nov Dec!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;

return "$day-$months[$mon]-$year";
}
In the auth.pl sub 'auth_logging' replace the '&get_date' with '&get_date2', here's my sub:
Code:
sub auth_logging {
# --------------------------------------------------------
# Logs an action to the database. Takes as input an action, and
# optionally a user id. If no user id is passed in, it get's one from
# the global $db_userid.

my ($action, $uid) = @_;
my ($time) = &get_time; # Change time/date format globally
my ($date) = &get_date2; # in get_time and get_date2.
if (!$uid) {
$db_userid ?
($uid = $db_userid) :
($uid = "UNKNOWN"); # Hopefully we shouldn't see this..
}
open (LOG, ">>$auth_log_file") &#0124; &#0124; &cgierr("unable to open log file: $auth_log_file. Reason: $!\n");
flock (LOG, 2) unless (!$db_use_flock);
print LOG "$uid $action at $time on $date from $ENV{'REMOTE_HOST'}\n";
close AUTH; # releases file lock.
}
Thats all I've did.
Quote Reply
Re: Problem with Date Format In reply to
Mart's solution should work.

I think the problem is (which I mentioned somewhere in a discussion that included Adrianda, Eliot and me), is the $time variable. It's used both in auth.pl and in the get_date subroutine. My suggestion was to rename the variable in sub get_date to $time1. Everyplace within sub get_date that you see $time, change it to $time1.

I'd really appreciate if someone would try it and let me know how it works.

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





Quote Reply
Re: Problem with Date Format In reply to
It works....*drumroll* GREAT!

Smile

Thanks, Mart.

I wonder if this problem is associated with another problem I am having on my NT, which is that session files in the auth are not being deleted within the six hour period I specified in the default.cfg files.

Mart, do you think that this fix will also solve this deletion of session files problem??

Thanks again.

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 August 10, 1999).]
Quote Reply
Re: Problem with Date Format In reply to
Thank you, Eliot!! Smile

I'll go make the change on my mod files.

I do appreciate your bringing it up. It was something I wasn't aware of, because I rarely look at log files.


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





Quote Reply
Re: Problem with Date Format In reply to
Well, the problem was actually identified by one of my clients. When I transfer over a database program to a data administrator or project manager, I don't track activity as thoroughly as I do in the projects I administrate.

So, I got an email a few days ago from a client asking why the date and time were not showing up correctly in their log files.

Smile

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
Quote Reply
Re: Problem with Date Format In reply to
JPeni et al,

Okay...may be we have not totally fixed the date problem yet. What I noticed is that while the log files are corrected...The "What's New" mod does not seem to work anymore...Opps!

What happens when I click on "List New Records", I get a "Search Error", which is:

Invalid date format: ''

I have the following codes for the "What's New" mod:

Code:
$days = 8;
$time = time() - ($days * 86400);

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;

$new = "$day-$months[$mon]-$year";

I have also linked the "List New Records" link in the following fashion:

Code:
<a href="$db_script_link_url&LastModified-gt=$new&vr=1&$db_key=*&Validate=Yes&sb=1&so=descend">

Be aware that I have renamed some of my routines, including view_records to vr to shorten the URL.

Smile

Any ideas??

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
Quote Reply
Re: Problem with Date Format In reply to
Did you make the other change to your file that is in the "What's New" mod? There's a bug in the script that prevents -gt and -lt dates from working correctly.

As a matter of fact, you might try installing all of the bugfix mods I have listed at http://www.jpdeni.com/dbman/Mods/bugfix.txt

It also fixes a bug in validate_records that doesn't allow a blank date field, as well as the fix we talked about in this thread with get_date.


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





Quote Reply
Re: Problem with Date Format In reply to
Hello, Carol...

Okay...I posted all the "bugfixes" in the file you posted.

I am still getting an Invalid date format error. At least now, it puts the date between the ' '. Here is the error I receive when I click on the List New Records link:

Invalid date format: '06-Aug-1999'

Again, here is what I have for the What's New additions in the html.pl file:

Code:
$days = 8;
$time = time() - ($days * 86400);

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;

$new = "$day-$months[$mon]-$year";

Here is an example record from my database file:

Code:
6|07-Aug-1999&#0124; &#0124;Medical|test|test|Full Time&#0124; &#0124;&#0124; &#0124;|test|teste|test|Oklahoma|
Bahrain|test|test&#0124; &#0124;&#0124; &#0124;No|elee|
07-Aug-1999&#0124; &#0124;No|7

What do I need to do with the What's New codes that will show a valid date format and also list the records within the LastModified time frame??

Thanks.


------------------
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
Quote Reply
Re: Problem with Date Format In reply to
Have you changed the date format in sub get_date and sub date_to_unix?

If not, I don't know what the problem is. 06-Aug-1999 is the same format as 07-Aug-1999, so it doesn't make any sense to me that you're getting an invalid date format.

Can I see your database in action?


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





Quote Reply
Re: Problem with Date Format In reply to
Here is the database (very beta, so excuse the dust):

anthrotech.com/cgibin/classifieds/index.cgi?db=opps&uid=default

(Click on the "List New Jobs" link.)

I did change the get_date sub-routine in the db.cgi file based on your instructions in that bugfix file you posted.

TIA.

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 August 14, 1999).]
Quote Reply
Re: Problem with Date Format In reply to
The only thing I can think to do now is to have you post your sub date_to_unix to make sure there's not a problem there.

In fact, that's the only place I can imagine there might be a problem.


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





Quote Reply
Re: Problem with Date Format In reply to
Hi, Carol.

Here is my sub date_to_unix:

Code:
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 (%months) = ("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4, "Jun" => 5,
"Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9, "Nov" => 10,"Dec" => 11);
my ($time);
my ($day, $mon, $year) = split(/ /, $_[0]);
unless ($day and $mon and $year) { return undef; }
unless (defined($months{$mon})) { return undef; }
use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900;
$time = timelocal(0,0,0,$day, $months{$mon}, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}

NOW, I am unable to add any new records. I get the following errors:


DatePosted (Invalid date format)
LastModified (Invalid date format)


I tried changing the default values to &get_date2 based on the date routine provided by mart.

Still didn't work. My new database is now virtually paralyzed. Frown

"If ain't one thing, it's another - Murphy's Law"

Any ideas of how to fix this would be greatly appreciated.

Thanks. Smile

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 August 14, 1999).]

[This message has been edited by Eliot (edited August 14, 1999).]

[This message has been edited by Eliot (edited August 14, 1999).]
Quote Reply
Re: Problem with Date Format In reply to
It's right here:

Code:
my ($day, $mon, $year) = split(/ /, $_[0]);

Here's what I think happened. You changed the date format in your db.cgi script, taking out the - and replacing it with a space. Then you copied the new sub get_date, but didn't make the same change.

The fix depends on what you want to do. If you want to have a space between the elements of the date, leave sub date_to_unix like it is and change the last line of sub get_date to

return "$day $months[$mon] $year";

Also, in the "What's New" section, change

$new = "$day-$months[$mon]-$year";

to

$new = "$day $months[$mon] $year";

OR -----------------

If you want to keep the - between the date elements, in sub date_to_unix, change

my ($day, $mon, $year) = split(/ /, $_[0]);

to

my ($day, $mon, $year) = split(/-/, $_[0]);

The format of all three sections must be the same.


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





Quote Reply
Re: Problem with Date Format In reply to
Carol,

Great...That fixed it. You may want to consider adding the sub date_to_unix
change in your bug fix mod. Smile

It is working now.

Thanks for your patience and cooperation. Smile

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
Quote Reply
Re: Problem with Date Format In reply to
Actually, it's not a bug in sub date_to_unix. The default format for the dates is with the hyphen between the date elements. I recall someone asking me relatively recently how to have a space between the elements. (I don't know if it was you or someone else.) I think you may have changed it in one part of your script, but not the other.


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





Quote Reply
Re: Problem with Date Format In reply to
Well, what I did was copy the get_date sub-routine in the bugfix file. I have not touched my date_to_unix sub-routine at all. So, the problems occurred after I applied the fixes stated in your bugfix file. Smile

Just a suggestion...May be a note or something to let users know that their date structures should be the same between the get_date and date_to_unix sub-routines.

Smile

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
Quote Reply
Re: Problem with Date Format In reply to
Okay. Smile I added dire warnings to both the bug fix and the what's new mods. Smile



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





Quote Reply
Re: Problem with Date Format In reply to
Thanks. Smile

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
Quote Reply
Re: Problem with Date Format In reply to
Hi

I applied Carol's bug fixes, including the date bug-fix, to a site I have been setting up at the start of the job.

I have just looked at the log files and all the dates are set to zero as far as unix is concerned:

Code:
chris logged on at 13:48:36 on 01-Jan-1970 from atomism.demon.co.uk

This is running with Linux on a Intel box.

Anyone got any ideas about this?

Cheers

Chris
> >