Jump to content

[SOLVED] How do I compare a php generated date (y-m-d) to a DATE from Mysql??


chewie

Recommended Posts

Question:

How do I compare a php generated date (y-m-d) to a DATE from Mysql??

 

I'm sure this has to be simpler than I'm approaching it as.

 

Basically I've already made a call to a database and table where I retrieve a field called expiredate.

 

I then want to compare it against today's date, and see if it equals today's date or is greater than...

 

I would think that I could do this simply by:

 

$expiredate = $row['expiredate'];
$currentdate =  date("Y-m-d");
if($expiredate >= $currentdate)
{.........}

 

Of course this does not appear to work.

What am doing wrong?

 

 

Link to comment
Share on other sites

The code you implied in the first post should work if $row['expiredate'] actually contains a DATE value. What symptom did you get that makes you think it did not work?

 

If you are trying to retrieve only rows WHERE expiredate is greater-than or equal to todays date, you would do that directly in your query using a WHERE clause -

 

.... WHERE expiredate >= CURDATE()

Link to comment
Share on other sites

Effectively when the code reaches that point in its execution i get a blank white page instead of the message I prescribed to be echo'd at that point.

You have an error! Switch error reporting on.

 

<?php
// top of page
ini_set('display_errors', 1); 
ini_set('error_reporting', E_ALL & ~E_NOTICE); 
?>

Link to comment
Share on other sites

Blank pages are usually due to fatal parse errors. You would need to set the error_reporting/display_errors settings in your master php.ini (and confirm that the settings are actually changed using a phpinfo() statement) in order to have php report and display fatal parse errors.

 

If your code is actually executing but is not producing any output, you would need to post your actual code if you want someone else to help determine what is causing the symptom. We cannot help with something without seeing it and there is not one 'fix' for any specific symptom because 10,000 different people could have written this thread and there could be something different wrong with each of their programs that are producing the same symptom.

 

You also need to set error_reporting to E_ALL because hiding notice messages would more than likely hide the reason why your code is not doing what you expect.

Link to comment
Share on other sites

Haha, if I thought about things correctly, I would have probably caught this sooner =)

$currentdate >= $expiredate

 

Really should be looking at..hmm is TODAY's date greater than or equal to whats in the system?

 

Der me, lol.

 

Now to get this conditional working..

 

$expires == 'yes' && $currentdate >= $expiredate

 

Didn't this use to work with PHP?

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.