Jump to content

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

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.