interval of sets

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

mattfrost
New php-forum User
New php-forum User
Posts: 2
Joined: Thu Jan 30, 2003 6:33 am
Location: Heidelberg, Germany

interval of sets

Postby mattfrost » Thu Jan 30, 2003 6:53 am

Hi there!

I am trying to solve a quite simple looking problem but can't get it:

I have stored in a db of events the times of the events. I need to find out how much time elapsed from one event to the other. So I need to calculate the interval between the events, i.e. I have to subtract one value from the other.
How can I do this when I have the following code:
<?php
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("pvdb",$db);

$result = mysql_query("SELECT * FROM warenaktion WHERE warenid=$warenid",$db);

echo "<table border=2 align=center valign=middle>";

echo "<tr><td>Aktion ID<td>Waren ID<td>Aktionart<td>Datum<td>Time<td>Differenz<td>Optionen</td></tr>";
while ($myrow = mysql_fetch_array($result))
{
echo "<TR><TD>".$myrow["aktionid"]."<TD>".$myrow["warenid"]."<TD>".$myrow["aktionart"]."<TD>".$myrow["datum"]."<TD>".$myrow["time"]."<td>";
echo "<TD><a href=\"warenaktionansicht.php?aktionid=".$myrow[aktionid]."\">Aktionsansicht</a><br />";
echo "<a href=\"warenaktionloeschen.php?aktionid=".$myrow[aktionid]."\">Aktion Loeschen</a><br />";
echo "<a href=\"eingabewarenaktion.php?warenid=".$myrow[warenid]."\">Neue Aktion</a><br />";
$time = $myrow["time"];
}



echo "</td></tr></table>";


?>

This means I have to subtract $myrow["time"] in the second line from $myrow["time"] in the first row.
Can anybody help?

Kind regards and thanks in advance.
Matt

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Sat Feb 01, 2003 2:04 pm

It depends on the time format.
Tell us what you have in the database and wich format you want for the resulting data.

mattfrost
New php-forum User
New php-forum User
Posts: 2
Joined: Thu Jan 30, 2003 6:33 am
Location: Heidelberg, Germany

Time format

Postby mattfrost » Tue Feb 04, 2003 6:27 am

Hi Joan!

The time format is the format which is generated under PHP with
echo time();
I thought it would be the most simple way to do it, because then I just have to divide through 60x60x24 to get the number of days. Is there a better way to do this?

Thanks a lot and kind regards, :lol:
Matt

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Tue Feb 04, 2003 10:28 am

You can use this function in many ways.
I think this is what you are looking for:

Code: Select all

<?php
//different format options, choose whatever you need
echo "<b>time() function: </b>".time()." <b>is the same as  strtotime ('now') function: </b>"; echo strtotime ("now"), "<br>";
echo ( strtotime ("12 March 2003") - strtotime ("now") )."<br>";
echo strtotime ("10 September 2000"), "<br>";
echo strtotime ("+1 week"), "<br>";
echo strtotime ("+1 week 2 days 4 hours 2 seconds"), "<br>";
echo strtotime ("next Thursday"), "<br>";
echo strtotime ("last Monday"), "<br>";
?>

I hope it helps!


Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron