|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Save your reputation with your customers. Learn how you can have embedding success with Advantage Database Server (ADS). |
|
#1
|
|||
|
|||
|
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! |
|
#2
|
|||
|
|||
|
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; } } ?> |
|
#3
|
|||
|
|||
|
Thanks I'll give it a try
Thanks I'll give it a try
![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > php date & time compare |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|