Drupal 7 - How to insert a unix timestamp into a database

Drupal newbie question. I am trying to insert the current date / time into an SQL database as a unix timestamp. It works in that I don't get an error message, but it just inserts the same value every time (2147483647). I am working on a local host (if that matters) and have tried the following: all to no avail:

format_date(strtotime('now'), 'custom', 'YYYY-MM-DD 00:00:00'); 

format_date(time(), 'custom', 'YYYY-MM-DD HH:MM:SS'); 

format_date(mktime(), 'custom', 'YYYY-MM-DD HH:MM:SS');
+5
source share
3 answers

PHP time() UNIX. strtotime ( "now" ). , , TIMESTAMP CURRENT_TIMESTAMP SQL, my_time_stamp_field = NOW().

... , mktime() http://www.php.net/manual/en/function.mktime.php unix - int, datetime, ( "YYYY-MM-DD HH: MM: SS", time()/unix timestamp/).

, .

+3

purplerice.

REQUEST_TIME - , Unix.

http://api.drupal.org/api/drupal/includes!bootstrap.inc/constant/REQUEST_TIME/7

    $inserted_val['other_value'] = 'other value';
    $inserted_val['last_update_date'] = REQUEST_TIME;
    db_insert('tablename')->fields($insert_fields)->execute();
+1

I know this is old, but if someone is stuck here, maybe I can help with another solution:

MySQL timestamp should be formatted as:

format_date(time(), 'custom', 'Y-m-d 00:00:00')
+1
source

All Articles