views:

27

answers:

4

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 ?

+2  A: 

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

But your question isn't all that clear.

Dennis Haarbrink
thanks man, I have updated the question , I will try your suggestion.
arnold
From what i can tell from your question this is exactly what you want. Say you have 2 records in your table, this query returns the record with the highest value in your datetime typed column.
Dennis Haarbrink
+1  A: 

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());
bluesmoon
A: 

use Select now() this may help u

for getting any value

Richa
A: 

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;
ceteras