Tag Archive: Erlang

Get timestamp in Erlang

timestamp() ->
{Mega,Sec,Micro} = erlang:now(),
(Mega*1000000+Sec)*1000000+Micro.

Provided that you want to increase or update the field YOUR_UPDATE_FIELD in table YOUR_TABLE with a key YOUR_TABLE_KEY_VALUE,
just use the following codes.

Query =
fun() ->
[OldRecord] = mnesia:read(YOUR_TABLE, YOUR_TABLE_KEY_VALUE, write),
P = OldRecord#YOUR_TABLE.YOUR_UPDATE_FIELD + 1,
NewRecord = OldRecord#operator{ YOUR_UPDATE_FIELD = P },
mnesia:write(NewRecord)
end,
{atomic, Result} = mnesia:transaction(Query).