Php Mysql date comparison

Posted on 2011-10-16
Medium Priority
Last Modified: 2012-05-12
Hi Experts

I have written the following statement that checks todays date against a date in our database.
If todays date 2011-10-16 is greater than database date 2099-10-19 then update access to lock account and redirect to page with instructions.

For some reason no matter what I do with the greater than or smaller than the update statement fire each time locking the account.

I only want the statement to fire if the date today is greater than the subscription date.

Am I doing the comparison correctly?

if(date("Y-m-d") > $row_rs_DWS_access_check['access_end_date']){
$sqlUpdateAccess = "update usrprofiles set usrprofiles.Active=0 where usrid = ".$_SESSION['kt_login_id'];
$result = mysql_query($sqlUpdateAccess);
header("Location: access.control.account.locked.php");

Open in new window

Question by:matthewdacruz
  • 2

Expert Comment

by:Sandeep Kothari
ID: 36975964
to compare date you need to use
strtotime - a php function


Expert Comment

by:Sandeep Kothari
ID: 36975968
LVL 34

Accepted Solution

Beverley Portlock earned 2000 total points
ID: 36976017
kshna said: "to compare date you need to use strtotime - a php function"

That is not strictly true. If dates are in the format YYYY-MM-DD then they can be compared directly with no need for other functions, but if the dates are in another format then strtotime is useful for converting them to integers for direct comparison.

There is another 'but' as well. strtotime will not work for any date past 2038 so the example given - 2099 - would fail with strtotime but would work if done as a string in YYYY-MM-DD format.

The newer PHP DateTime class is more likely to help as it does not have the 2038 restriction



Author Closing Comment

ID: 36977979
Thank you for your direction, it steered me to the best solution for what I was working on.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question