Jump to content

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

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.