The data in timestamp format is read from MySQL to PHP and is not a number and is a readable date.

Source: Internet
Author: User
echo $row [0];
echo Time ();
$row is the time that is read from the database.
Show Results:
2013-05-02 18:50:15
1367492310

My data type is not set, right? Or is MySQL or PHP automatically converted? How can I read the timestamp directly? I know I can use time to convert a function, but I wonder if I could read the timestamp directly. It feels very 2 to convert back and forth.


Reply to discussion (solution)

Read it with the MySQL client first

Read it with the MySQL client first
I tried it with the command line, and all of the time-date types are read directly and are all readable. is not an integer.

It seems that PHP has been turned into a timestamp.

That's you. The field type is a datetime type.

That's you. The field type is a datetime type.

mysql> use testdatabase changedmysql> CREATE TABLE time_test (ID int,time TIMESTAMP); Query OK, 0 rows affected (0.47 sec) mysql> insert into time_test (id,time) VALUES (0,now ()); Query OK, 1 row affected (0.05 sec) mysql> select * from time_test;+------+---------------------+| ID |    Time |+------+---------------------+| 0 | 2013-05-03 11:18:51 |+------+---------------------+1 row in Set (0.00 sec) mysql> INSERT into time_test (id,time) values (0,123); Query OK, 1 row Affected (0.00 sec) mysql> SELECT * from time_test;+------+---------------------+| ID |    Time |+------+---------------------+| 0 |    2013-05-03 11:18:51 | | 0 | 2000-01-23 00:00:00 |+------+---------------------+2 rows in Set (0.00 sec) mysql> INSERT into Time_test (id,time) value S (0,unix_timestamp (now ())); Query OK, 1 row affected, 1 warning (0.14 sec) mysql> select * from time_test;+------+---------------------+| ID |   Time |+------+---------------------+| 0 |    2013-05-03 11:18:51 | | 0 |    2000-01-23 00:00:00 | | 0 | 0000-00-00 00:00:00 |+------+---------------------+3 rows in Set (0.00 sec) mysql>

Select ID, time+0 as time from Time_test
$row [' time '] is 20130503112940

This manual is very clear, what is the use of guessing?

the timestamp column records the date and time when it is used for an INSERT or update operation. If you do not assign a value, the first timestamp column in the table is automatically set to the date and time of the most recent operation. You can also set the timestamp column to the current date and time by assigning a null value.

The timestamp value returns a string that appears as a ' yyyy-mm-dd HH:MM:SS ' format, and the display width is fixed at 19 characters. If you want to get a numeric value, you should add +0 in the timestamp column.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.