Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/199043-date-difference/
Share on other sites

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)

Link to comment
https://forums.phpfreaks.com/topic/199043-date-difference/#findComment-1044798
Share on other sites

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

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/199043-date-difference/#findComment-1045627
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.