Page 2 of 2

Posted: Wed Nov 16, 2005 9:32 am
by mhouldridge
Ok,

I know how to echo, but the code does not work. I dont have a clue what to change there.

regards,

Posted: Wed Nov 16, 2005 9:49 am
by Burrito
ok, a little bit different than the sample I posted your situation is:

try:

Code: Select all

$row = mysql_fetch_array($sql); //get a row from our result set 
$dateone = $row['start_date']; 
$datetwo = $row['end_date']; 
$daysleft = ((strtotime($datetwo) - strtotime($dateone))/86400); 
echo $daysleft;

Posted: Wed Nov 16, 2005 10:08 am
by mhouldridge
Yes, that did it... thank you.

I also need to calculate the number of days left from today's date and the end_date

I now I need to implement NOW() however this will format my date like 2005-10-21 and not 01-10-2005

Any ideas?

Posted: Wed Nov 16, 2005 10:10 am
by mhouldridge
Hmm,,


Actually scrap that. I have the start date and end date there I would like to run a script when the number of days left reaches 7.

I think I know how to do this.....

I will let you know if I get stuck.

---- Much appreciated is your help! ----

Posted: Wed Nov 16, 2005 10:30 am
by BDKR
Burrito wrote: Created for a reason this field type was. Fit your bill exactly it will.
LOL! Funny as hell this response is. LO*****'L!

Posted: Wed Nov 16, 2005 10:41 am
by mhouldridge
I need to create a variable for today's date in the format;

2005-11-16

Any ideas?

This is so that I can run a script which emails me with the number of days left.

Posted: Wed Nov 16, 2005 10:43 am
by Burrito

Code: Select all

$today = date("Y-m-d");

Posted: Wed Nov 16, 2005 10:49 am
by mhouldridge
Thank you!

Posted: Wed Nov 16, 2005 10:51 am
by patrikG
why not let MySQL do that dirty stuff. Keeps your PHP clean:

Code: Select all

SELECT DATEDIFF('2003-11-20','2004-12-31');
all in the manual: http://dev.mysql.com/doc/refman/4.1/en/ ... tions.html

search for DATEDIFF on that page

Posted: Wed Nov 16, 2005 10:56 am
by mhouldridge
Hi,

I wonder if you could help me with a for loop. Here is the code;

Code: Select all

for($i = 0; $i < $numofrows; $i++) {
    
$row = mysql_fetch_array($sql); //get a row from our result set 


 $today = date("Y-m-d"); // Set today's date as variable
 $notify = 7; // Set notify variable to 7
 $datetwo = $row['end_date']; //set dattwo variable to the field value from the query
 $daysleft = ((strtotime($datetwo) - strtotime($today))/86400); 
	
	echo "<TR bgcolor=\"efefef\" onmouseover=this.className=\"test2\" onmouseout=this.className=\"test\" class=\"test\" onclick=this.className=\"test3\" class=\"test3\">\n";    
	echo "<TD><a href='viewasset.php?varl=".$row['id']."' class=\"blue5\">".$row['id']."</a></font></TD><TD>".$row['name']."</TD><TD>".$row['start_date']."</TD><TD>".$row['end_date']."</TD><TD>".$daysleft."</TD>\n"; 
    echo "</TR>\n";
		}
	echo "</TABLE>\n";
I want to display the days left in my $daysleft value for the loop. It is not working yet.

Posted: Wed Nov 16, 2005 10:58 am
by Burrito
use a while loop to loop your results instead you should.

/me likes patrikG's solution better anyway 8O

Posted: Wed Nov 16, 2005 8:55 pm
by trukfixer
patrikG wrote:why not let MySQL do that dirty stuff. Keeps your PHP clean:

Code: Select all

SELECT DATEDIFF('2003-11-20','2004-12-31');
all in the manual: http://dev.mysql.com/doc/refman/4.1/en/ ... tions.html

search for DATEDIFF on that page
DATEDIFF() was added in MySQL 4.1.1. - if your mysql is < 4.1.1 you're out of luck :)