DeanWhitehouse Posted September 20, 2008 Share Posted September 20, 2008 I have this code for the difference in days , but i think i am doing something wrong as it is not returning the correct result. <?php $today1 = $rows['started_on']; $today1 = date("d.m.Y",strtotime($today1)); $f_date1 = $rows['completed_on']; $f_date1 = date("d.m.Y",strtotime($f_date1 )); $difference = intval(($f_date1 - $today1)/86400+1); echo $difference; ?> The $rows are stored in this format (2008-08-07 21:43:10), any ideas. Note: i will need it to work out the amount of days from when i started to when i finished, that may go into another month. Quote Link to comment https://forums.phpfreaks.com/topic/125126-differnce-in-days/ Share on other sites More sharing options...
BlueSkyIS Posted September 20, 2008 Share Posted September 20, 2008 problem may be you're using the date() function to put the times into "d.m.Y" format before trying subtract. Quote Link to comment https://forums.phpfreaks.com/topic/125126-differnce-in-days/#findComment-646713 Share on other sites More sharing options...
AndyB Posted September 20, 2008 Share Posted September 20, 2008 Does it help to know that the date() function allows you to find the day of the year (starting from zero)? Quote Link to comment https://forums.phpfreaks.com/topic/125126-differnce-in-days/#findComment-646715 Share on other sites More sharing options...
DeanWhitehouse Posted September 20, 2008 Author Share Posted September 20, 2008 Bluesky, i didnt write the code i found it (google) so i dont know, any help would be good. And AndyB that may help, but doing it using that would be the long way i beleive? Quote Link to comment https://forums.phpfreaks.com/topic/125126-differnce-in-days/#findComment-646719 Share on other sites More sharing options...
discomatt Posted September 20, 2008 Share Posted September 20, 2008 You're getting the date from a MySQL database? mysql> SELECT TO_DAYS(NOW()) - TO_DAYS('2008-08-07 21:43:10') as `difference`; +------------+ | difference | +------------+ | 44 | +------------+ 1 row in set (0.00 sec) Quote Link to comment https://forums.phpfreaks.com/topic/125126-differnce-in-days/#findComment-646721 Share on other sites More sharing options...
DeanWhitehouse Posted September 20, 2008 Author Share Posted September 20, 2008 would that be $sql = "SELECT * FROM news SELECT TO_DAYS(".$new_time.") - TO_DAYS(".$old_time.") as `difference`;" Quote Link to comment https://forums.phpfreaks.com/topic/125126-differnce-in-days/#findComment-646724 Share on other sites More sharing options...
discomatt Posted September 20, 2008 Share Posted September 20, 2008 No... $sql = "SELECT *, (TO_DAYS(NOW()) - TO_DAYS(`completed_on`)) as `difference` FROM news;" And you use $rows['differece']; Quote Link to comment https://forums.phpfreaks.com/topic/125126-differnce-in-days/#findComment-646728 Share on other sites More sharing options...
DeanWhitehouse Posted September 20, 2008 Author Share Posted September 20, 2008 ok, thnks will try it Quote Link to comment https://forums.phpfreaks.com/topic/125126-differnce-in-days/#findComment-646731 Share on other sites More sharing options...
DeanWhitehouse Posted September 20, 2008 Author Share Posted September 20, 2008 bit of a prob this is my code $sql = "SELECT *, (TO_DAYS(".$rows['started_on'].") - TO_DAYS(`".$rows['completed_on']."`)) as `difference` FROM sites WHERE id = '$site_id' AND member_id = '$id'";// this is my problem, the vars need to be retireved from the db , do i need to reset the pointer if so how? $query = mysql_query($sql); $number = mysql_num_rows($query); ?> <p align="center" style="text-align:left; margin-left:5px;"> <?php if($number == 0) { echo "Either the site is not registered , or the site is not registered to this username. Please check and try again."; } else { while($rows = mysql_fetch_assoc($query)) { echo $rows['difference']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/125126-differnce-in-days/#findComment-646733 Share on other sites More sharing options...
DeanWhitehouse Posted September 21, 2008 Author Share Posted September 21, 2008 I dont think any one actually saw the comment so here it is this is my problem, the vars need to be retireved from the db , do i need to reset the pointer if so how? corresponds to this line $sql = "SELECT *, (TO_DAYS(".$rows['started_on'].") - TO_DAYS(`".$rows['completed_on']."`)) as `difference` FROM sites WHERE id = '$site_id' AND member_id = '$id'"; Quote Link to comment https://forums.phpfreaks.com/topic/125126-differnce-in-days/#findComment-646751 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.