0

i want to create a timestamp by which i can know which post is modified when and all. in mysql databse, i made a coloumn called lastmodified, with type as timestamp. now, when i am updating the data in db, i want to update the current timestamp in last modified. how to do so? also could anyone please tell me, if any function exits for comparing these timestamps.

$now = time();

$query = "update storydb set lastmodified = '$now' where story_id = '$story_id'";
mysqli_query($con, $query);
2
  • Please don't re-engine the wheel. Use mysql now() instead of your var for datetime ;) set lastmodified = now() Commented Dec 10, 2014 at 10:38
  • just change the attribute of your column to on update CURRENT_TIMESTAMP and everytime somethings updates on that row..the timestamp will automatically changed Commented Dec 10, 2014 at 10:40

3 Answers 3

3

time() returns UNIX Timetamp in integer format e.g. 1223485636.

You want it in 2014-12-10 02:02:36

Use MySQL now() function instead of $now

$query = "update storydb set lastmodified = now() where story_id = '$story_id'";

now() is a MySQL function that returns current Time Stamp (including date).

Sign up to request clarification or add additional context in comments.

Comments

2

No, its not unix timestamp that should be used in there, just a normal NOW() should suffice:

$query = "UPDATE storydb SET lastmodified = NOW() WHERE story_id = ?";
$update = $con->prepare($query);
$update->bind_param('s', $story_id);
$update->execute();

Comments

0

To insert current unix timestamp in data base

$time = time();
$qry = 'update db_name' set column_name = $time where condition;
mysql_query($qry);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.