nold
nold

Reputation: 498

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 ?

Upvotes: 0

Views: 9524

Answers (5)

LibertyTech
LibertyTech

Reputation: 25

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.

Upvotes: 0

ceteras
ceteras

Reputation: 3378

If you want to see the record with the latest datetime column in it, do this:

select * from your_table order by your_datetime_column desc limit 1;

Upvotes: 0

PHP
PHP

Reputation: 1709

use Select now() this may help u

for getting any value

Upvotes: 1

bluesmoon
bluesmoon

Reputation: 4320

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());

Upvotes: 1

Dennis Haarbrink
Dennis Haarbrink

Reputation: 3760

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

But your question isn't all that clear.

Upvotes: 3

Related Questions