phpmyadmin/MySQL - dynamic date field?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Please be gentle; I am a relative newbie for php/MySQL, and most of what  
I am doing is based on being self-taught using someone else's  
well-written code, and my own googling the answers to my questions.

I'm doing a php/MySQL page that reads data out of a MySQL database.  
Longer term, I'll do a data-entry screen allowing me to modify the  
database or add new records.  For now, I'm just using phpmyadmin to data  
enter stuff.

Is there a way to set up a date field, Last_Update, that would  
automatically update to today's date any time a record was added or  
changed using phpmyadmin?

Not sure if I'm asking the question clearly.  What I want would be that,  
let's say that I add a new record today, April 23.  The Last_Update  
field for the record would automatically be April 23.  If I go in and  
modify and part of that record on April 29, Last_Update automatically  
changes to April 29 for that record.

If that's not possible, then how in php/MySQL would I display on a web  
page "Information last updated on mm/dd/yyyy" based on the contents of  
the database?

Re: phpmyadmin/MySQL - dynamic date field?

Quoted text here. Click to load it

This is the purpose of the field type 'timestamp'.  If you want
only the date portion, you can get it with date_format() in the
MySQL query.  

The *first* timestamp field will be updated to the current time if
the record is changed, and that field isn't explicitly set.  If a
record is inserted, the timestamp field will be the current time
unless another non-null value is explicitly inserted (insert null
or leave the field out of the field list for insert).

Leave off the "using phpmyadmin" part.  You get that behavior if
the record is changed with a query, with or without phpmyadmin.
*Can* you modify just one field with phpmyadmin?  If you type in
an explicit query, yes, if you use neato GUI stuff, you may be
setting all the fields you didn't change back to the values they
had before, which defeats the action of the timestamp.

                    Gordon L. Burditt

Re: phpmyadmin/MySQL - dynamic date field?

Quoted text here. Click to load it

Simply use the MySQL field type of "TIMESTAMP" and set it to null on
any updates to the table... TIMESTAMP fields are automagically set to
the current time when the value passed to it is null.

PS this post should actually be on comp.databases.mysql. I don't care
much but some people in usenet are real pricks about stuff like this.

Site Timeline