Gossamer Forum
Home : General : Databases and SQL :

Date and Time fields Questions

Quote Reply
Date and Time fields Questions
If I set a column (say Last_Login) to type=>'date' then this just records the date?

If I set this column to type=>'timestamp' then this records the date and the time each time the record is accessed, right??

I want to set this column with the current date/time only when something else is true, like with my Last_Login for when I user logs in.

I understand there is a DATETIME type used in the LSQL Links table (default 0000-00-00 00:00:00).

So I guess my question is, how do I set a column with the DATETIME field to the current DATETIME reported by the server (only when a condition is true, not automatically like timestamp)?

Pheww.. I hope that makes sense.


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: May 29, 2002, 1:26 PM
Quote Reply
Re: [Ian] Date and Time fields Questions In reply to
DATETIME is actually a MySQL column type.

If you only want the time recorded for certain logins, then I would recommend setting the time portion to 00:00:00 for those that you do not want to record. And set the time for the other users.

Some date manipluation codes have been posted in the LINKS SQL over time. Look at the Date.pm module, which contains most, if not all, the date manipulation subs that you need.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Stealth] Date and Time fields Questions In reply to
Setting it as an *INT column and storing epoch time is more flexible IMO.

Last edited by:

Paul: Jun 2, 2002, 3:37 PM
Quote Reply
Re: [Paul] Date and Time fields Questions In reply to
Thanks both. I currently have it working as a DATETIME column, thanks to looking through Alex's search logger code.

But can see that an INT may be more flexible.... I understand there are date calculation functions built into MySQL, but you can always do more with a straight number. I guess storing a date in long form, needs to be formated when displaying of course, but I should be able to work that out!


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Date and Time fields Questions In reply to
The simplest formatting can be done with localtime.

print scalar localtime;

This takes epoch time as an argument but uses time by default so it is the same as:

print scalar localtime(time());

So you can do like:

print scalar localtime($epoch);

My favorite module for manipulating times/dates is POSIX.

http://www.opengroup.org/...99/xsh/strftime.html

eg..

Code:
use POSIX qw/strftime/;
print POSIX::strftime("%H:%M:%S", localtime);

Last edited by:

Paul: Jun 2, 2002, 3:53 PM
Quote Reply
Re: [Paul] Date and Time fields Questions In reply to


Paul, very comprehensive list on this page... thank you for sharing this link!

This may sounds like an extemely dumb question, but is POSIX just another PERL module that would be installed on my server?


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Date and Time fields Questions In reply to
POSIX should be there by default. You can read more about POSIX at:

http://www.perldoc.com/...5.6.1/lib/POSIX.html