Jump to content

SHOW BY tstamp


shane85

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/202921-show-by-tstamp/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/202921-show-by-tstamp/#findComment-1063434
Share on other sites

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.