Page 1 of 1
Dates
Posted: Fri Sep 08, 2006 12:18 pm
by icesolid
I wanted to know if anyone had any ideas on comparing two dates.
I have two dates which are dynamically pulled from a database (stored as DATE format), below are just two example dates:
Code: Select all
<?php
$date1 = "2006-08-11";
$date2 = "2006-08-20";
?>
I want to figure out how to have PHP compare the two and give me the number of days in-between the dates and store it in a variable.
Code: Select all
<?php
$total_days = answer here;
?>
Posted: Fri Sep 08, 2006 12:22 pm
by wtf
it's going to be much easier to handle this on the database end. Take a look at the mysql's
datediff(exp1, exp2) function
Posted: Fri Sep 08, 2006 1:16 pm
by icesolid
I tried the using your suggestion this is what I have and I am not producing a correct result.
Code: Select all
$time_service = mysql_query("SELECT DATEDIFF('2006-08-11','2006-08-20') FROM cases WHERE control_number='$control_number'");
When I echo out $time_service this is my result:
When I try and put this result in an array (mysql_fetch_array) I get
Array as my result.
Posted: Fri Sep 08, 2006 1:21 pm
by feyd
viewtopic.php?t=29341
After as many posts as you have icesolid, should I need to remind you to use
Posted: Fri Sep 08, 2006 1:21 pm
by volka
That's because mysql_query does not return a string or an array but a resource.
See
http://de2.php.net/myql_fetch_array
Sorry
Posted: Fri Sep 08, 2006 1:28 pm
by icesolid
I'm sorry feyd, honestly.
I have figured out my problem, well both of them, I am an idiot and my programmatic error.
Posted: Fri Sep 08, 2006 2:45 pm
by wtf
Also don't forget the 'AS' part
Code: Select all
SELECT DATEDIFF('2006-08-11','2006-08-20') AS alias_name
Posted: Mon Sep 11, 2006 11:06 am
by wtf