compare dates

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

compare dates

Post by nite4000 »

I am needing some assistance with how to compare dates

I need to take a date someone signes up and compare to current date and then if its more then 15 days have it suspend

I am can the quesry to suspend and all but getting it to compare the dates is what i need help with

If anyone can provide a example or something it would help.

Thanks
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Re: compare dates

Post by William »

Code: Select all

 
 
// Set variables
$fifteen_days = 1296000;
 
if ( ( time() + $fifteen_days ) < $input_timestamp ) {
    // The date is later than 15 days in the future.
}
 
Do something like that. In terms of setting $input_timestamp, you can use http://www.php.net/strtotime or http://www.php.net/mktime or a few others. Check the manual. :-)
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Re: compare dates

Post by nite4000 »

what is $input_timestampe is that the same as the current date

What I need to do is take teh date in a table in a field called joindate and chk to see if its been more then 15 days to the current date.

I also need to know how to get the number for 15 days i see 1296000 how is that done also what would it be for a day since i will need to test this script

Thanks
William wrote:

Code: Select all

 
 
// Set variables
$fifteen_days = 1296000;
 
if ( ( time() + $fifteen_days ) < $input_timestamp ) {
    // The date is later than 15 days in the future.
}
 
Do something like that. In terms of setting $input_timestamp, you can use http://www.php.net/strtotime or http://www.php.net/mktime or a few others. Check the manual. :-)
User avatar
paqman
Forum Contributor
Posts: 125
Joined: Sun Nov 14, 2004 7:41 pm
Location: Burnaby, BC, Canada

Re: compare dates

Post by paqman »

You can go

Code: Select all

$input_timestamp = time();
to get the current unix timestamp (for the time when the server completed the request).

60 seconds/minute * 60 minutes/hour * 24 hours/day * 15 days = 1296000 seconds (15 days)
Post Reply