Jump to content

Need to calculate number of days between dates then return a date


simcoweb

Recommended Posts

Summary:

 

* ad posters can create one ad per every 7 days

* their email address is the user id i'm working off of to determine if they've already submitted an ad

* say they try to submit an ad 3 days after submitting a previous ad

* I want a message to say 'You can not post an ad until Saturday... blah blah'.

 

I need to find the date they submitted their current ad which is no problem since it's inserted into the database when they created the ad. Now, it's 3 days later and they want to submit another. I need to determine if it's been 7 days or not and, if not, display an error and, if so, let it go through. Here's what I have but it doesn't work (or why else would I be posting... eh? lol)

 

<?php
$date1 = '11/25/06';
$date2 = "now";
$start = strtotime($date1);
$end = strtotime($date2);
$days = ($date2 - $date1) / (60*60*24);
$diff = number_format($days);
echo $diff;
?>

 

This is not 100% accurate to how it would actually be written but it's my working model to get the math right. The logic here line by line is:

 

1. get the date from the current db entry

2. get today's date

3. calculate the time stamp for the date of their ad posting

4. calculate the time stamp for today

5. calculate the difference

6. print the difference

 

Obviously something is not right as it returns -0 as the value. Help anyone?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.