In Oracle you can easily perform arithmetic on dates in your SELECT statement to limit your results based on how old the entry is. For example, If I was going to pull out the usernames, messages, and dates from a database in which the posted date was within the last 7 days I could easily do that with a SQL SELECT statement.
In this example, POST_TABLE is my database table, and POST_DATE is the date of the post. I can use a SELECT statement similar to the one below to get all the messages within the last 7 days and order the results by the post date.
SELECT USERNAME, MESSAGE, POST_DATE FROM POST_TABLE WHERE (SYSDATE - POST_DATE < 7) ORDER BY POST_DATEAs you can see, it is a really simple solution that is much more elegant then the PHP based solution I discussed yesterday. Either way there are certain situations in which both solutions have their place. If you have any questions, comments, suggestions, or even complaints, leave them in the comments.
Shane
No comments:
Post a Comment