Jump to content


Photo

query most recent record by date and time


  • Please log in to reply
4 replies to this topic

#1 NoDoze

NoDoze

    Advanced Member

  • Members
  • PipPipPip
  • 199 posts

Posted 07 January 2009 - 05:35 PM

How would you do a mysql query to post the most recent date and time in a table?
...only that entry.

Thanks.

#2 Maq

Maq

    Advanced Member

  • Moderators
  • 9,364 posts
  • LocationPennsylvania, USA

Posted 07 January 2009 - 07:29 PM

ORDER BY date DESC LIMIT 1;

tjmothy

ini_set ("display_errors", "1");
error_reporting(E_ALL);

#3 NoDoze

NoDoze

    Advanced Member

  • Members
  • PipPipPip
  • 199 posts

Posted 09 January 2009 - 02:23 PM

ok, something wierd is going on...

I have the code line like you have above, like this:
$sql = "SELECT * FROM hicks ORDER BY date DESC LIMIT 1";

But it's not pulling the most recent one...

#4 NoDoze

NoDoze

    Advanced Member

  • Members
  • PipPipPip
  • 199 posts

Posted 09 January 2009 - 04:14 PM

ok, I added another column for timestamp and having it use that to pull the most recent. For some reason I think the date XX-XX-XX and XXXX hour format is having issues.

#5 corbin

corbin

    Advanced Member

  • Staff Alumni
  • 8,129 posts

Posted 09 January 2009 - 11:32 PM

If the column is a string datatype (char to be more correct) it will sort oddly (well, not oddly, but not what you would expect).


You should really use a date or datetime column for dates or dates including time.
Why doesn't anyone ever say hi, hey, or whad up world?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com