简体   繁体   English

从日期中提取信息(varchar)并转换为输出

[英]Extract Information From Date (varchar) and transmute into output

Background 背景

I am extending a web application which must 'extract' information from a varchar variable in a mySQL table. 我正在扩展一个Web应用程序,该应用程序必须从mySQL表中的varchar变量中“提取”信息。 Now although I am quite familiar the is the most convoluted way to actually store the date in the column, I cannot change the table structure currently, or it will 'break' the rest of the system. 现在,尽管我很熟悉这是将日期实际存储在列中最复杂的方法,但是我目前无法更改表结构,否则它将“破坏”系统的其余部分。 So with this information given, how can I output (using php) this field as so: 因此,根据给出的信息,我如何这样输出(使用php)该字段:

Column Data 列数据

2013-05-12 13:18:14

Output Data 输出数据

$html .= "<td>" . $row['created_on'] . "</td>";

should print: 应该打印:

Instance1: 5/12/13
Instance2: May 12th, 2013
Instance3: 5/12/13, 1:18 PM

You can do it like this: 您可以这样做:
First turn it into its timestamp value by strtotime() , then you can show it in many ways. 首先通过strtotime()将其转换为其时间戳记值,然后可以通过多种方式显示它。 Follow this link: date() 请点击以下链接: date()

$col = '2013-05-12 13:18:14';
$timestamp = strtotime($col);

$instance1 = date('m/d/y',$timestamp);
$instance2 = date('M jS Y',$timestamp);
$instance3 = date('m/d/y , h:i:s A',$timestamp);

echo $instance1.'<br>';
echo $instance2.'<br>';
echo $instance3;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM