Jump to content

Date Created and Date Updated fields


MargateSteve

Recommended Posts

Can anyone point me in the direction of a good tutorial on Date Created and Date Updated fields?

 

Quite simply they would need to do what it says on the tin, ie. one field automatically updates with the date the record was created and the other automatically updates with the date the record was updated.

 

As a further complication, as it will be used on an existing site, I would ideally like to be able to manually update the Date Created field if required, although an additional field where a date could be manually entered and supercede the Date Created in queries would be a way around this.

 

Thanks in advance

Steve

Link to comment
Share on other sites

This is easy to do and don't know why no-one has answered.  :confused:

 

But first. How are you going to use this? Will it be for retrieving records? And will you need to be able to fid things by the month or the year or both and how about the day, will that be needed for a search?

------------------------------------------------------

 

Use phpMyAdmin to add to coloumns at the end of the rows. That way nothing already in play will be hurt (changed).

<?php
$mydate = date("F j Y");
echo $mydate;
?>

should be run before for all querys now. Not the echo part. And the $mydate added to them. A simple ex.

 

Create date_created and date_updated.

FOR CREATED ROW:

INSERT INTO table_name (column1, column2, column3,...,'date_created')

VALUES (value1, value2, value3,...,$mydate)

 

When data is updated:

UPDATE example SET age='22',...,date_updated=$mydate  WHERE age='21'

 

 

Link to comment
Share on other sites

@Steve:  One feature that could be of interest for you also is the usage of a TIMESTAMP field with DEFAULT CURRENT_TIMESTAMP and  ON UPDATE CURRENT_TIMESTAMP properties enabled, that allow you to eliminate the UPDATE part of the previous posted code because in that case the update of that field is automatic.

 

more information and examples here

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.