shane85 Posted May 26, 2010 Share Posted May 26, 2010 hey guys so im trying to make a news system...in my database table news, I have id(int10) tstamp(timestamp) subject(text) message(text) so basically, I write a message, it records the date that I write it, etc etc etc. What I want to do is have side links so that I can view articles I have posted by month. So. January would be like <a href="news.php?month=01">January</a> etc or something like that....being that tstamp stores as 2010-05-25 20:41:16 for example, how can I make my links for jan./feb/mar etc link to the correct months?? Quote Link to comment https://forums.phpfreaks.com/topic/202921-show-by-tstamp/ Share on other sites More sharing options...
kalivos Posted May 26, 2010 Share Posted May 26, 2010 Assuming you are using MySQL, the timestamp format can vary depending on the version you are running. If you are just starting this project, I would suggest switching to datetime. If you wish to stick with timestamp, you can try the following: $sql = "SELECT * FROM `news` WHERE tstamp >= '2010-".$month."-01' AND tstamp <= '2010-".$month."-30'; There are several enhancements that you will probably want to do: Verify $month is a number in the range of 1-12 Verify that it is padded with a leading zero to make it two characters long Instead of using "30" as the last day, make it dynamic to the last day of the month (maybe 31 or 28). Here's a link to the MySQL docs page: http://dev.mysql.com/doc/refman/5.1/en/timestamp.html Hope that helps, -Kalivos Quote Link to comment https://forums.phpfreaks.com/topic/202921-show-by-tstamp/#findComment-1063434 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.