PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 2nd, 2002, 06:22 AM
omar omar is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 18 omar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question php date & time compare

Hi guys,
I'm working on a web project using php which has an
application form, and I need some help with
comparing dates.

Let's assume that I already have a function that
get the last date and time a user of a specific
ip address made a post. I basically want to limit
a user (based on their ip) to one (1) post
per day (24 hrs) or once every two days.

I just need help in creating a function
that can compare the two dates.

example

function can_post($lastPost, $now) {
'...
}

It would also be nice if I could tell when
is the next time that the can post.

thanks!

Reply With Quote
  #2  
Old October 2nd, 2002, 11:42 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 16
Try something like this:

<?
/* Last post was October 1, 2002 @ 5:10AM */
// mktime is as follows (hour, minute, second, month, day, year)
$lastpost = mktime(5,15,0,10,1,2002);

echo 'Last Post was: ', date("M-d-Y H:m:s a", $lastpost), '<br>';

if (canPost($lastpost, 24)) {
echo 'The time now is: ', date("M-d-Y H:m:s a", time()), '<br>';
print 'ok to post';
} else {
echo 'next post time is ', date("M-d-Y H:m:s a", $lastpost+(3600*24));
}


function canPost($lastpost, $diff)
{

// Lets turn hours into seconds
$diff = $diff*3600;

// When can the user post next?
$nextpost = $lastpost+$diff;

// What time is it now?
$timenow = time();


// Is the time now greater than the
// next available post time?
if ($timenow > $nextpost) {
return true;
} else {
return false;
}

}


?>

Reply With Quote
  #3  
Old October 2nd, 2002, 05:08 PM
omar omar is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 18 omar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks I'll give it a try

Thanks I'll give it a try

Reply With Quote
  #4  
Old June 15th, 2009, 11:58 AM
dcox dcox is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 1 dcox User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 4 sec
Reputation Power: 0
You might want to change "m" to "i" for minutes.

echo 'Last Post was: ', date("M-d-Y H:i:s a", $lastpost), '<br>';

if (canPost($lastpost, 24)) {
echo 'The time now is: ', date("M-d-Y H:i:s a", time()), '<br>';
print 'ok to post';
} else {
echo 'next post time is ', date("M-d-Y H:i:s a", $lastpost+(3600*24));
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > php date & time compare


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap