Time and time again.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
serambin
Forum Newbie
Posts: 9
Joined: Wed Nov 13, 2002 11:27 pm
Location: Haughton, LA 71037

Time and time again.

Post by serambin »

Is there a simple way to activate a timestamp in MySQL without passing a variable from the php script? What I want to do is have a timestamp field in the database which (NOW)'s every time a new record is added.

Thanks,

Stan :?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

When you do your update just reset the field along with anything else you're changing:

Code: Select all

UPDATE table SET value='something', lastupdate=NOW() WHERE ID=whatever
Mac
mester
Forum Newbie
Posts: 5
Joined: Fri Aug 02, 2002 3:40 am

Re: Time and time again.

Post by mester »

serambin wrote:Is there a simple way to activate a timestamp in MySQL without passing a variable from the php script? What I want to do is have a timestamp field in the database which (NOW)'s every time a new record is added.

Thanks,

Stan :?
Create a column TIMESTAMP. It will be updated every time you do some modification to the record. Read the manual! :!:
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Good point, forgot about that:
http://www.mysql.com/doc/en/DATETIME.html

Mac
serambin
Forum Newbie
Posts: 9
Joined: Wed Nov 13, 2002 11:27 pm
Location: Haughton, LA 71037

Manual Labor

Post by serambin »

Sorry, I did read the manual,

I was using a Timestamp(14) without being specified explicitly in an INSERT or LOAD DATA INFILE statement. However, when setting up the field in MySQLAdmin, the column was set to null even after I 'appeared' to have sucessfully changed it to non null (even deleted and recreated). That's why I was looking for another solution. I finally am using datetime and setting it in the code explicitly.

Thanks for the kind replies,

Stan
Post Reply