Jump to content

[SOLVED] MySQL and dealing with dates...


me1000

Recommended Posts

Hello,

 

The user will have the ability to determine the expiration period of an entry. (1 week, 2 weeks, 1 month, 2 months, 3 months, 6 months)

 

The problem is I am unsure of how to filter the results to only show the entries that are not past the expiration.

 

Is there an easy SQL or PHP command to convert dates to make them much easier to work with?

 

Thanks,

 

 

Link to comment
Share on other sites

If want to store useful dates in a database, also use the ISO standard format - yyyy-mm-dd. That allows you to sort in calendar order, do 'math', and you can use whatever format you want to display the date as needed.

Link to comment
Share on other sites

ok, so basically im out of luck making it any easier on me.

At first it doesnt seem that hard, however the more I think about it, what if in those 7 days the month changes? I have to write that into my code. Now what happens if the year also changes within that 7 days too?

 

is there no easy(er) way to manage this?

Link to comment
Share on other sites

ok,

So when I attempt to work with this, im not having a lot of luck

echo date("2008-05-26", strtotime('+1 year'));

 

from what I understand this should return

"2009-05-26" right?

 

Im getting the exact same date as I entered into it...

"2008-05-26"

 

im not sure what the problem is here though...

Link to comment
Share on other sites

So this will only work if I use PHP generated dates?

 

this could be a problem, because the date will be stored in the database, and pulled out when it needs to be calculated.

 

 

 

EDIT: im just going to mark this topic as solved, because for the moment I can just do the math on the dates before they get stored in the DB...

 

Link to comment
Share on other sites

So this will only work if I use PHP generated dates?

 

No. Suppose you retrieve the date from the database as the variable named $the_date.

 

list($y,$m,$d) = explode("-", $the_date); // gets y, m, and d from the stored date
$some_date = date("Y-m-d", mktime(0,0,0,$m,$d,$y+1)); // $some_date is one year later

 

Does that shed some light on things?

Link to comment
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.