By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,606 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,606 IT Pros & Developers. It's quick & easy.

Compare dates in php

100+
P: 250
How can i compare two days in php and my sql? In my web application user should register a date and the validity period(ex.5 days). I want to count days and cancel the user operations after that validity period. How can i do that?
Feb 1 '08 #1
Share this Question
Share on Google+
2 Replies


stepterr
100+
P: 157
How can i compare two days in php and my sql? In my web application user should register a date and the validity period(ex.5 days). I want to count days and cancel the user operations after that validity period. How can i do that?
Check out the PHP function strtotime. Here is a quick sample of how you could use it.

[PHP]$exp_date = "2006-01-16";
$todays_date = date("Y-m-d");
$today = strtotime($todays_date);
$expiration_date = strtotime($exp_date);
if ($expiration_date > $today)
{
$valid = "yes";
}
else
{
$valid = "no";
}[/PHP]
Feb 1 '08 #2

ifedi
P: 60
Check out the PHP function strtotime. Here is a quick sample of how you could use it.

[PHP]$exp_date = "2006-01-16";
$todays_date = date("Y-m-d");
$today = strtotime($todays_date);
$expiration_date = strtotime($exp_date);
if ($expiration_date > $today)
{
$valid = "yes";
}
else
{
$valid = "no";
}[/PHP]

To evaluate the validity using e.g. 5 days:

[PHP]
$reg_date = "2008-02-08";//can be dynamically obtained by inserting NOW() into a database table field of the time DATE or DATETIME
$todays_date = date("Y-m-d");
$today = strtotime($todays_date)/3600*24;
$start_date = strtotime($reg_date)/3600*24;
if ($today - $start_date >= 5)
{
$expired= "yes";
}
else
{
$expired= "no";
}[/PHP]
Feb 8 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.