Jump to content

Recommended Posts

Hi All,

 

Hope some kind soul can help!?

 

I've a users table in a CMS i'm building. This users table has a registration_date that stores data in datetime format.

When a user registers, they can select whether they want a normal or premium account. As such, they will need to pay for the premium account.

I've built a script which list all users and the date joined using

$query = "SELECT CONCAT(last_name, ', ', first_name) as name, DATE_FORMAT(registration_date,'%d %M %Y') as date, email  FROM users ORDER BY $order_by LIMIT $start, $display";

I then show the date next to the username. All's ok so far. What I want to do is set it so that if a year has passed since the join date, an email is sent reminding them of payment is due and 30 days prior to this, a warning email is sent.

I know a cron jobs used for automating, however, at the mo, I can't even get the date difference working.

 

This is the code I've got so far:

		$todays_date = time(); 
		echo $todays_date .' todays';
		echo '<hr/>';
		$joined_date = mktime($row['date']);
		echo $joined_date .' joined';		
		echo '<hr>';

		$dateDiff = $todays_date - $joined_date;
		echo $dateDiff .' date diff';
		echo '<hr>';
		$time_convert = (60*60*24);
		echo $time_convert . ' time convert';
		$fullDays = floor($dateDiff/$time_convert);   
		echo '<hr>';
		echo "Differernce is $fullDays days"; 

It keeps saying 0 days though! Once I can get the date calc working I can then start working on the email code & then a cron job to automate it all.

 

Any help is much appreciated!

mktime($row['date']);

 

should be:

$joined_date = strtotime($row['date']);

 

http://be.php.net/mktime requires it's parameters to be integers and if they are not they are converted to them abiding by the type conversion rules.

 

print (int) "hello world"; // 0

 

Thus: mktime($row['date']); equals mktime(0); which equals the current date in seconds. Therefor $joined_date ~ $todays_date. Then you convert to days which is 0 as the difference between today and today is 0 ;)

Thanks ignace, do I need to do any of the following:

		echo $dateDiff .' date diff';
		echo '<hr>';
		$time_convert = (60*60*24);
		echo $time_convert . ' time convert';
		$fullDays = floor($dateDiff/$time_convert);  

As changing that one line makes the following:

Differernce is 14447 days

Which isn't right.

 

Sorry!  :-\

$todays_date = time();
echo $todays_date .' todays';
echo '<hr/>';
$joined_date = strtotime('01 Juli 2009');
echo $joined_date .' joined';
echo '<hr>';

$dateDiff = $todays_date - $joined_date;
echo $dateDiff .' date diff';
echo '<hr>';
$time_convert = (60*60*24);
echo $time_convert . ' time convert';
$fullDays = floor($dateDiff/$time_convert);
echo '<hr>';
echo "Differernce is $fullDays days";

 

gives me (on 22 Juli 2009):

 

1248271225 todays
--------------------------
1246446540 joined
--------------------------
1824685 date diff
--------------------------
86400 time convert
--------------------------
Differernce is 21 days

Hi ignace,

 

Many thanks for the reply. That does seem to work until I change:

$joined_date = strtotime('01 Juli 2009');

To:

$joined_date = strtotime($row['date']);

 

I'm setting $joined date as follows:

DATE_FORMAT(registration_date,'%d %M %Y') as date

$joined_date = $row['date'];

Do I need to alter this as registration_date is in my db as date_time

 

Thanks again!

If I print that line from the db

		// Retrieve the date the member joined
		$joined_date = $row['date'];
		echo $joined_date .'- joined date<br/>';

I get

22 July 2009- joined date

 

Thanks and apologies

 

What does it print if you execute the code? Still 14447?

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.