1

i get error when i want to insert current time to my table-field date,

i get this error PDOException: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1345724717' for column 'date' at row 1: INSERT INTO {users_history} (uid, nid, points, date, reason) VALUES ('31', '107', '2', '1345724717', 'session'); Array ( ) in points_node_insert() (line 57 of /home/www/live_project/htdocs/sites/all/modules/custom/points/points.module).

i have table like this:

uid int
nid int
points int
date datetime
reason enum

this is my query(this query works fine if i delete date field)

  $date = time();
    db_query("INSERT INTO {users_history} 
       (uid, nid, points, date, reason) VALUES 
       ('$uid', '$nid', '$points_for_post', '$date', '$reason')");
2

The 'datetime' value assumes the "YYYY-MM-DD HH:MM:SS" formatting, if I got it, you're trying to insert a 'timestamp'

|improve this answer|||||
  • yep you are right, changed to $date1 = date("Y-m-d H:i:s", time()); and its working – Petro Popelyshko Aug 23 '12 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.