Page 1 of 1
clarification: time() in PHP
Posted: Tue Aug 09, 2005 7:01 am
by raghavan20
I have a database that has got a Time field with datatype timestamp(14)
but if I try to do sth like:
insert into ChatUsers_tbl values('NULL', 'Raghavan', '".time()."');
time() is of 10 digits but doesnot get into the mysql database which is of 14 digits.
Instead when I insert I get 'fourteen zeros' in the field.
What is the best way to store a timestamp?
Posted: Tue Aug 09, 2005 7:06 am
by Grim...
I always store it as a long interger.
Posted: Tue Aug 09, 2005 7:56 am
by timvw
Might want to read
http://dev.mysql.com/doc/mysql/en/datetime.html
Code: Select all
// using MySQL current timestamp
$query = "INSERT INTO foo VALUES (NOW());";
// using PHP current timestamp
$query = "INSERT INTO foo VALUES (FROM_UNIXTIME(" . time() . "))";
I believe
http://adodb.sf.net has a class dedicated to time handling...
Posted: Tue Aug 09, 2005 8:51 am
by raghavan20
I was trying something like this but it still thinks it as wrong format
I have got the field with timestamp(14) in Mysql.
ex output: 20050809164830(14 digits)
1. What do you think is the problem now?
2. The only difference btw DateTime and Timestamp in mysql is the former one has got separators btw each part...is it true?
the later has got no separators btw any of the parts?
I am actually looking for time and date in a field and it could be sorted.
Posted: Tue Aug 09, 2005 8:57 am
by feyd
just use NOW() in the SQL like timvw said..