Jump to content

Date & Time??


Round

Recommended Posts

If you're using MySQL then just use the [color=green]DATE_FORMAT()[/color] function.

[code]<?php
// SQL statement to get date from database
$sql = "SELECT DATE_FORMAT(date_column_name, '%h:%i %p') AS time FROM table_name";

$result = mysql_query($sql);
if (!$result){
  echo mysql_error(); // If error, why couldn't we execute $sql
}
else {
  $time = mysql_result($result, 0, 0); // If success, assign the date to the variable $time
}

// Echo the time
echo $time;
?>[/code]

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/30622-date-time/#findComment-141028
Share on other sites

cheers huggie, but I'm not sure thats going to work for me
heres what i've got so far
[code]$sql = "select * from events_table where location =\"$location\" ";

#exe query
$rs = mssql_query( $sql, $conn )
or die( "Could not execute Query");

#search for matches
$num = mssql_num_rows ($rs);
if ($num !=0)
{
$list = "<table align= \"center\" border=\"0\" cellpadding=\"4\" width=\"100%\">";
$list .= "<tr>";
$list .= "<th class=table>Whats on</th>";
$list .= "<th class=table>Location</th>";
$list .= "<th class=table>Booking code</th>";
$list .= "<th class=table>Planner</th>";
$list .= "<th class=table>Date & Time</th>";
$list .= "</tr>";

#retrieve data
while ( $row = mssql_fetch_array( $rs ) )
{
if ( $row["event_date"] != null)
{ $event_dt = date("l, jS F Y",
strtotime($row["event_date"]))." ".$row["start_time"];
}
else
{ $event_dt = "TBC";
}
$list .= "<tr>";
$list .= "<td class=table>".$row["event"]."</td>";
$list .= "<td class=table>".$row["location"]."</td>";
$list .= "<td class=table>".$row["booking_code"]."</td>";
$list .= "<td class=table>".$row["planner_name"]."</td>";
$list .= "<td class=table>".$event_dt."</td>";
$list .= "</tr>";
}
$list .= "</table>";

#list details if matches found or display no matches found msg
#Below produces name etc at top of page
echo( "<center><p><b><br>Here is the list of up an coming events"<br><br>");
echo(  $list . "<br>" );
}
else
{ echo ("<br><center>There are no events</center>");
}
mssql_close ( $conn ); [/code]

the problem is the field start_time has both a date and time in it, but the date is always incorrect. as i cant sift trough and remove this on the physical data in the db I was hoping to just strip it away. I wouldn't know where to start to insert another if statement.
Link to comment
https://forums.phpfreaks.com/topic/30622-date-time/#findComment-141040
Share on other sites

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.