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
Link to comment
Share on other sites

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??

Link to comment
Share on other sites

[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" . ;-)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.