Urgent PHP: the createtime field type in the database is datetime. how can I query data within a period of time based on this?

Source: Internet
Author: User
Urgent PHP: the createtime field type in the database is datetime. how can I convert the createtime field type to datetime, which is year, month, day, minute, and second based on the data database type in this query period? There is a lot of data, a good conversion, but so much?


Reply to discussion (solution)

select unix_timestamp('2011-4-19 12:00:00');

select unix_timestamp('2011-4-19 12:00:00');

My database is not in the timestamp format, but in the datetime format.

My database is not in the timestamp format, but in the datetime format.
Didn't you say you want to convert it into a timestamp? Unix_timestamp can convert your datetime format to a timestamp.


My database is not in the timestamp format, but in the datetime format.
Didn't you say you want to convert it into a timestamp? Unix_timestamp can convert your datetime format to a timestamp.
If the database is not a single piece of data, how can we convert so much data?

If the database is not a single piece of data, how can we convert so much data?
Select unix_timestamp (time field); the time field is the time field that you want to convert in the database.

You just need to directly compare it.

Select * from table1 where create_time> '2017-03-21 00:00:00'

Queries can be directly compared
For example, select * from table where createtime> = '2017-01-01 00:00:00 'and creattime <'2017-01-31 00:00:00 ';

This can be done if you want to batch display
Select *, unix_timestamp (createtime) as createtime from table;

Select * from table where createtime> = '2017-01-01 00:00:00 'and creattime <'2017-01-31 00:00:00 ';

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.