简体   繁体   中英

how to get latest date and time in php and mysql using a select statement

how to get latest date and time in php and mysql using a select statement? is that possible My field type is data time it looks like this "2010-06-08 01:41:27" . any help is appreciated guys.

edit: sorry not so clear with my question...(ugh!) basically I have a column in my table which has a field of datetime (did I say it right, it has a data type of datetime?) , these are fill up already with some data , All I need to do is get the latest in that field, is there a need to compare it ?

i think you are looking for this: select max(datetime_column) from table

But your question isn't all that clear.

In SQL, use this:

SELECT NOW();

to get the current date/time. In PHP, use the time() function.

You can also insert the current time into a database field using this SQL:

INSERT INTO `mytable` (`date`) VALUES (NOW());

use Select now() this may help u

for getting any value

如果要查看其中包含最新日期时间列的记录,请执行以下操作:

select * from your_table order by your_datetime_column desc limit 1;

With your question, it shows that you really wanted to get the latest input from your database which has the present date and time. I think this should solve your problem

SELECT * FROM table_name WHERE DATE(`date_and_time_column_name`)= CURDATE();

This will surely do the job.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM