473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Compare dates in php

250 100+
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
2 3181
stepterr
157 100+
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
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

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

Similar topics

4
by: Gleep | last post by:
Hey Guys, I've got a table called Outcomes. With 3 columns and 15 rows 1st col 2nd col 3rdcol outcome date price There are 15 rows...
3
by: jrc4728 | last post by:
I have a MySQL table with the date stored in three fields as string values like this. (sorry, its imported data) str_yy str_dd str_mm ------------------------ 05 01 04 05 ...
4
by: alexis | last post by:
Hi, In a form I have the curent date <input name="datetoday" type="hidden" value="<? echo date("d/m/Y"); ?>"> and <input type=text name="datebox" size=15> The date format is d/m/Y...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
9
by: Rich | last post by:
Thanks for the Help in my previous post. I've been working on this and it's almost what I want. I want to obtain the user's current age by comparing their date of birth (user inputs) to the...
9
by: Rimuen | last post by:
Have two text form with dates i need to compare before submitting, the second should always be a date later the first one. Anyone have a script for this ?? Thanks.......
1
by: godsella | last post by:
First i have two stored procedures, i have passed the values of each one into two different arraylists of dates. how can i compare the two arraylists of dates? Thanks in advance
5
by: Tom | last post by:
It appears that you can't compare two dates in DotNet. You must use ToString and compare the strings. Is that the only reliable way? Try this: Dim dteOne As Date =...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
6
by: cd123 | last post by:
Hi, I used Date object of Javascrips to compare two dates like one is the from date and the other is to date. var obj1 = new Date(from date); var obj2 = new Date(to date); then i used...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.