PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
icesolid
Forum Regular
Posts: 502 Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY
Post
by icesolid » Fri Sep 08, 2006 12:18 pm
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;
?>
Last edited by
icesolid on Fri Sep 08, 2006 12:23 pm, edited 3 times in total.
wtf
Forum Contributor
Posts: 331 Joined: Thu Nov 03, 2005 5:27 pm
Post
by wtf » Fri Sep 08, 2006 12:22 pm
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
icesolid
Forum Regular
Posts: 502 Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY
Post
by icesolid » Fri Sep 08, 2006 1:16 pm
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Sep 08, 2006 1:21 pm
viewtopic.php?t=29341
After as many posts as you have icesolid, should I need to remind you to use
icesolid
Forum Regular
Posts: 502 Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY
Post
by icesolid » Fri Sep 08, 2006 1:28 pm
I'm sorry feyd, honestly.
I have figured out my problem, well both of them, I am an idiot and my programmatic error.
wtf
Forum Contributor
Posts: 331 Joined: Thu Nov 03, 2005 5:27 pm
Post
by wtf » Fri Sep 08, 2006 2:45 pm
Also don't forget the 'AS' part
Code: Select all
SELECT DATEDIFF('2006-08-11','2006-08-20') AS alias_name
wtf
Forum Contributor
Posts: 331 Joined: Thu Nov 03, 2005 5:27 pm
Post
by wtf » Mon Sep 11, 2006 11:06 am