[英]Hide Characters from PHP MySQL Query result
I want to hide the time frame (00:00:00) which is appearing in the result of the query below in the columns "Start Date" and "End Date". 我想隐藏在“开始日期”和“结束日期”列下面的查询结果中出现的时间范围(00:00:00)。
Result of the query is displaying this way: 查询结果以这种方式显示:
Department City/University Start Date End Date
1. Building Science Miami 2011-12-28 00:00:00 2012-02-03 00:00:00
The code looks like this: 代码如下:
$date_start = firstOfMonth();
$date_end = lastOfMonth();
$query = " SELECT Department, `Start Date`, `End Date` FROM facultytravel WHERE Country='".$country."' AND `Start Date`<='".$date_end."' AND `End Date`>='".$date_start."' ORDER BY `Start Date` ASC";
$result = mysql_query($query);
$num = 1;
while($row = mysql_fetch_array($result)){
print "<tr>";
print "<td>".$num.". ".$row['Department']."</td>";
print "<td>".$row['City/University']."</td>";
print "<td>".$row['Start Date']."</td>";
print "<td>".$row['End Date']."</td>";
print "</tr>";
$num++;
}
You need to format the date they are two methods 您需要格式化日期,这是两种方法
Using SQL 使用SQL
SELECT DATE_FORMAT(`End Date`, '%Y-%M-%D');
Or 要么
Using PHP 使用PHP
$time = strtotime($your_query['End Date']);
$date = date("Y-m-d",$time );
You can include that in a PHP function 您可以将其包含在PHP函数中
尝试这个:
$query = " SELECT Department, CAST(`Start Date` AS DATE) as `Start Date`, CAST(`End Date` AS DATE) AS `End Date` FROM facultytravel WHERE Country='".$country."' AND `Start Date`<='".$date_end."' AND `End Date`>='".$date_start."' ORDER BY `Start Date` ASC";
You could use explode() as you might want to use the time component one day! 您可以使用explode(),因为您可能希望有一天使用时间组件! eg:
例如:
$start_datetime = explode(' ', $row['Start Date']);
$end_datetime = explode(' ', $row['End Date']);
Then access these parts as: 然后以下列方式访问这些部分:
$row['Start Date'][0]
Will be: 2011-12-28 将是:2011-12-28
$row['Start Date'][1]
Will be: 00:00:00 将是:00:00:00
$row['End Date'][0]
Will be: 2012-02-03 将是:2012-02-03
$row['End Date'][1]
Will be: 00:00:00 将是:00:00:00
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.