Jump to content

MYSQL Select last row in a sequence of date fields


mrplatts

Recommended Posts

Welll...if you are storing the dates as timestamps, then you can easily do this by:
[code]
<?php
 
  $query = $db->query("SELECT TOP 1 * FROM table ORDER BY date DESC");
  $result = $db->fetch_array($query);

?>[/code]

If you're not storing them in the database as timestamps...but as formatted dates...then "God..please....why do people do this to themselves?!!"  :P
Hmm... I did save them in MYSQL date format yyyy-mm-dd, but it would make much more sense to use timestamps for this reason.  Also, I find myself going back and forth from timestamps to that date format annoying.  Pretty silly when I can just use
date("d-m-Y", $stamp);

So there isn't an easy way to order by date? why have a specific format for date in MySQL then??

[quote author=mrplatts link=topic=117026.msg477216#msg477216 date=1165006301]
Hmm... I did save them in MYSQL date format yyyy-mm-dd, but it would make much more sense to use timestamps for this reason.  Also, I find myself going back and forth from timestamps to that date format annoying.  Pretty silly when I can just use
date("d-m-Y", $stamp);

So there isn't an easy way to order by date? why have a specific format for date in MySQL then??


[/quote]

The reason why using timestamps makes more sense, is because you can always format for display purposes later. You can still query for formatted dates...but there is less flexibility that way, and you only really need it formatted for display purposes. And if you use timestamps, you can always do that AFTER you have easily queried, sorted, and displayed your results by "date" . ;-)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.