MargateSteve Posted May 3, 2011 Share Posted May 3, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235460-date-created-and-date-updated-fields/ Share on other sites More sharing options...
sunfighter Posted May 8, 2011 Share Posted May 8, 2011 This is easy to do and don't know why no-one has answered. 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' Quote Link to comment https://forums.phpfreaks.com/topic/235460-date-created-and-date-updated-fields/#findComment-1212527 Share on other sites More sharing options...
MargateSteve Posted May 10, 2011 Author Share Posted May 10, 2011 Thanks for that. I will have a little play with it later. To be honest, at the moment, they would be used just for my reference, but I would, in the future, possibly use it to show a list of recently updated pages. Thanks again Steve Quote Link to comment https://forums.phpfreaks.com/topic/235460-date-created-and-date-updated-fields/#findComment-1213426 Share on other sites More sharing options...
mikosiko Posted May 10, 2011 Share Posted May 10, 2011 @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 Quote Link to comment https://forums.phpfreaks.com/topic/235460-date-created-and-date-updated-fields/#findComment-1213438 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.