I want to store current timestamp (date+time).
I have ste field data type as timestamp in mysql.
I use mktime() to store current timestamp but it stores 000000000000 not correct timestamp.
What could be the problem :ehh:
Printable View
I want to store current timestamp (date+time).
I have ste field data type as timestamp in mysql.
I use mktime() to store current timestamp but it stores 000000000000 not correct timestamp.
What could be the problem :ehh:
Use NOW() in your sql query to insert the current time.
As an aside, you should try to do as much logic work in the SQL as you can, this reduces the communication between application and DBMS.
For example:
Code:insert into `guestbook` (
`id`,
`name`,
`time`
)
values (
last_insert_id(),
'Fred',
now()
);
Just to add if you are storing timestamps in MySQL then when you want to retrieve them you should use MySQL to format them instead of PHP for the same reason that penagate said
http://dev.mysql.com/doc/refman/5.0/...functions.html
okay
But then how to compare two timestamps now ?
because now function returns 14 digits timestamp
and mktime returns 13 digits.
Well, you can't compare timestamps from two different sources.
You can also just retrieve the current time from MySQL like this:
Code:select now();
Have a look at the date time functions in SQL. You can use UNIX_TIMESTAMP(date) function to convert it back to a timestamp.