mrplatts Posted December 1, 2006 Share Posted December 1, 2006 I have a MySQL table keyed by date. In my script I want to find out the last date in the table. (they are sequetial) I can't seem to find anything online to help. I just need to get the date field from the row at the end of the sequence. Thanks, Rich Quote Link to comment Share on other sites More sharing options...
Caesar Posted December 1, 2006 Share Posted December 1, 2006 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 Quote Link to comment Share on other sites More sharing options...
keeB Posted December 1, 2006 Share Posted December 1, 2006 heheh..pseudo-code: [code=php:0]$var = select max(date) from tbl_Table$q = select * from tbl_Table where date=$var[/code] Quote Link to comment Share on other sites More sharing options...
mrplatts Posted December 1, 2006 Author Share Posted December 1, 2006 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 Link to comment Share on other sites More sharing options...
Caesar Posted December 1, 2006 Share Posted December 1, 2006 [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" . ;-) Quote Link to comment Share on other sites More sharing options...
mrplatts Posted December 2, 2006 Author Share Posted December 2, 2006 alright I'm convinced. I'll rewrite a little, it will make life much easier. Rich Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.