I-AM-OBODO Posted April 19, 2010 Share Posted April 19, 2010 Hi all. In my database i want to pull out the dates from two different tables. What i did was as pull out the date from one table and assigned it to a variable and used session to pass it to another page which has the second table that contains the second date etc. $first_date=$_Session['date1']; $query="SELECT * FROM table2 WHERE name = 'name'"; $result = mysq_query('$query'); blah blah blah Note: the date format is 200-10-10 How do i get the difference between the dates? Hope am making sense here, or a better way of getting the required results. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/199043-date-difference/ Share on other sites More sharing options...
aeroswat Posted April 19, 2010 Share Posted April 19, 2010 Hi all. In my database i want to pull out the dates from two different tables. What i did was as pull out the date from one table and assigned it to a variable and used session to pass it to another page which has the second table that contains the second date etc. $first_date=$_Session['date1']; $query="SELECT * FROM table2 WHERE name = 'name'"; $result = mysq_query('$query'); blah blah blah Note: the date format is 200-10-10 How do i get the difference between the dates? Hope am making sense here, or a better way of getting the required results. Thanks Convert to timestamps and subtract Then do math to figure out how many of whatever was between them (seconds,minutes,hours,days,weeks,etc) Quote Link to comment https://forums.phpfreaks.com/topic/199043-date-difference/#findComment-1044798 Share on other sites More sharing options...
I-AM-OBODO Posted April 20, 2010 Author Share Posted April 20, 2010 Thanks for the tip. Got it now. Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/199043-date-difference/#findComment-1045422 Share on other sites More sharing options...
I-AM-OBODO Posted April 21, 2010 Author Share Posted April 21, 2010 The problem now is how to make the result of my calculation (date diff) apear in al the rows in my table. This is wat i hav in my code <?php $query = "select date, date_order from table where description = '$description'"; $result = (mysql_query($query)); while ($newArray=(mysql_fetch_array($result))){ $date = $newArray['date']; $date_order = $newArray['date_order']; $time1=strtotime($date_order); $time2=strtotime($date); $check=date("d:m:Y",$time2); $check2=date("d:m:Y",$time1); $diff = intval(($time1 - $time2) / 86400 + 1)); echo $diff; ?> the problem is i have many field in my tables that match query but query outputs only one result. I want the difference be linked to each row in table Thanks Quote Link to comment https://forums.phpfreaks.com/topic/199043-date-difference/#findComment-1045627 Share on other sites More sharing options...
AdRock Posted April 21, 2010 Share Posted April 21, 2010 Why don't you use JOIN on the tables in one query Quote Link to comment https://forums.phpfreaks.com/topic/199043-date-difference/#findComment-1045630 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.