Adding a timestamp..

Talk about programming tricks and examples

Moderators: ne_moj, zewa, vadimako, ne_moj, zewa, vadimako

daviddelmonte
Master
Master
Posts: 159
Joined: Feb 23rd, '10, 15:06

Adding a timestamp..

Postby daviddelmonte » Aug 7th, '10, 22:45

What's the best way to add an automatic timestamp for any record that is added/edited?

Thanks

Slawek68
Junior
Junior
Posts: 18
Joined: Sep 11th, '09, 08:17

Re: Adding a timestamp..

Postby Slawek68 » Sep 18th, '10, 13:19

HI
I do not know the answer to your question, but it seems to me that there is no such possibility.
Since I also have this need I have a proposal for the authors of Datagreed
to enter to the edit mode for a hidden field a new property named for example "quotes" and values of true or false,
which would be responsible for adding quotes at values in instructions INSERT and UPDATE.
Then we could define the field type:

Code: Select all

"FieldName" => array ("header" => "Name", "type" => "hidden", "default" => "NOW()", "value" => "NOW()", "quotes" => "false")

the effect of which would be an instruction in the following form:

Code: Select all

UPDATE TableName SET FieldName = NOW() WHERE id = rid

Such a solution would provide huge opportunities because in the properties of the "default" and "value" the whole subqueries could be written.

daviddelmonte
Master
Master
Posts: 159
Joined: Feb 23rd, '10, 15:06

Re: Adding a timestamp..

Postby daviddelmonte » Sep 19th, '10, 06:09

Great idea. I look forward to Apphp response.

administrator
Site Admin
Site Admin
Posts: 5990
Joined: Jan 7th, '09, 23:18
Contact:

Re: Adding a timestamp..

Postby administrator » Sep 19th, '10, 08:42

"timestamp" works automatically every time you update your record, so you even don't need to define such field.

Slawek68
Junior
Junior
Posts: 18
Joined: Sep 11th, '09, 08:17

Re: Adding a timestamp..

Postby Slawek68 » Sep 21st, '10, 05:30

Hi,administrator.
Of course you're right, but:
1. I wrote an application where I need a timestamp for individual fields, and not for the whole record;
2. I suggested a solution that can have a much wider application than just a timestamp, because this way you can write other functions and even entire subqueries;
Of course I can modify the code datagrid itself but in the long run such behavior prevents from updating datagrid.

daviddelmonte
Master
Master
Posts: 159
Joined: Feb 23rd, '10, 15:06

Re: Adding a timestamp..

Postby daviddelmonte » Sep 21st, '10, 05:37

administrator wrote:"timestamp" works automatically every time you update your record, so you even don't need to define such field.


Can you give an example of how to access a timestamp from a record?

Thanks

administrator
Site Admin
Site Admin
Posts: 5990
Joined: Jan 7th, '09, 23:18
Contact:

Re: Adding a timestamp..

Postby administrator » Sep 21st, '10, 06:55

1. Simply define field as a timestamp, don't define it in a list of Edit mode fields.
2. Define this field in a list on fields for View mode
3. Update the record in datagrid and see what you get in View mode.

daviddelmonte
Master
Master
Posts: 159
Joined: Feb 23rd, '10, 15:06

Re: Adding a timestamp..

Postby daviddelmonte » Sep 21st, '10, 08:39

got it.. Many thanks


Return to “Programming Tricks”