Jump to content

[SOLVED] clause based on date/time


AV1611

Recommended Posts

I have a database that returns a field with a date and time that looks like this:

 

12/04/2007 07:45:03

 

I need a simple clause that says if the time is before noon then A else if the time is after noon then B

 

I could split the date from the time in a string then split the time by the : but there is a much easier way, right?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/47107-solved-clause-based-on-datetime/
Share on other sites

Still not working ???

 

it works but quits after a few rows:

 

datafield --> what is produced

 

10/04/2007 07:14:39 -->7

10/04/2007 16:07:14 -->16

11/04/2007 07:13:54 -->7

11/04/2007 17:01:20 -->17

12/04/2007 07:45:03 -->7

12/04/2007 17:00:17 -->17

13/04/2007 09:25:54 -->16

13/04/2007 17:10:24 -->16

14/04/2007 08:18:06 -->16

14/04/2007 18:24:03 -->16

15/04/2007 07:37:01 -->16

 

Here is my script ( I used G not g in the date()...)

mysql_select_db($database);
$result = mysql_query("Select * from glucose")or die('Died: '.mysql_error());
while($row=mysql_fetch_array($result)){
$date_str = $row[1];
$hour = date('G',strtotime($date_str));
echo $row[1]." -->".$hour." <br/>";
if ($hour <= 11)
	{echo "<tr><td class='e'>".$row[0]."</td><td class='v'>".$row[1]."</td><td class='e'>".$row[2]."</td><td class='v'>".$row[3]."</td></tr>";}
else
	{echo "<tr><td class='e'>".$row[0]."</td><td class='v2'>".$row[1]."</td><td class='e'>".$row[2]."</td><td class='v'>".$row[3]."</td></tr>";}
}
echo "</table></center>";

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.