Jump to content

Recommended Posts

I have a date that a member signs up which is input as

date(Y-m-d)

in the row called 'tempdate'.

The member has 15 days to finish some work while there. After that, he can't access the page.

When the member goes to his page, I want it to tell him how many days he has left to finish.

 

I have been trying to work with basic math like this

$expdate = strtotime("+15 days", $row['tempdate']);
$exp_date = date("Y-m-d", $expdate);
$days = $exp_date - date("Y-m-d");

 

obviously this does not work. I have played around with other ideas that also don't work.

$expdate = strtotime("+15 days", $row['tempdate']);
$today = strtotime(date(Y-m-d));
$days = $expdate - $today;

But then i don't know how to change the $days into a number.

 

Does anyone have an example or idea on how to make this work. ONe of my concerns is if the member signs up at the end of the year and his exp date is in the following year.

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/74636-solved-math-using-dates/
Share on other sites

In case anyone wants it, i finally found some code.

 

	<?php
	$results = mysql_query("SELECT * FROM pages WHERE id = '".$_GET['ID']."'", $dbconnect);
	$row = mysql_fetch_assoc($results);

	//set your year, month, day, hour, minute, second you want to countdown to.
	//ONLY CHANGE FROM HERE
	$tempdate = strtotime($row['tempdate']);
	$expdate = strtotime("+15 days", $tempdate);

	$year=date("Y", $expdate);
	$month=date("m", $expdate);
	$day=date("d", $expdate);
	$hour="00";
	$minute="00";
	$second="00";
	//TO HERE. PLEASE DO NOT CHANGE ANY OTHER BIT OF CODE

	$time=mktime($hour, $minute, $second, $month, $day, $year);

	$timecurrent=date('U');
	$cdtime=$time-$timecurrent;
	$cdminutes=$cdtime/60;
	$cdhours=$cdtime/3600;
	$cddays=$cdhours/24;
	$cdmonths=$cddays/30;
	$cdyears=$cddays/365;
echo "Your page can be viewed for ".number_format($cddays)." more days.";
	?>

As you can see, you can echo years, months, days, hours, minutes, and seconds.

I hope this helps someone else.

 

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.