Automatically populate a timestamp field in PostgreSQL when a new row is inserted

To populate the column during insert, use a DEFAULT value: CREATE TABLE users ( id serial not null, firstname varchar(100), middlename varchar(100), lastname varchar(100), email varchar(200), timestamp timestamp default current_timestamp ) Note that the value for that column can explicitly be overwritten by supplying a value in the INSERT statement. If you want to prevent … Read more

mysql timestamp column

You can use the timestamp column as other posters mentioned. Here is the SQL you can use to add the column in: ALTER TABLE `table1` ADD `lastUpdated` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ; This adds a column called ‘lastUpdated’ with a default value of the current date/time. When that record is updated … Read more

How to convert python timestamp string to epoch?

There are two parts: Convert the time string into a broken-down time. See How to parse ISO formatted date in python? Convert the UTC time to “seconds since the Epoch” (POSIX timestamp). #!/usr/bin/env python from datetime import datetime utc_time = datetime.strptime(“2009-03-08T00:27:31.807Z”, “%Y-%m-%dT%H:%M:%S.%fZ”) epoch_time = (utc_time – datetime(1970, 1, 1)).total_seconds() # -> 1236472051.807 If you are … Read more