为什么 MySQL DATE_FORMAT 打印空白结果?
在过去的几个小时里,我一直在尝试使用 DATE_FORMAT
格式化 MySQL 时间戳,但它没有做任何事情!
Perl 代码:
use CGI;
use DBI;
my $q = new CGI;
# Database connection goes here
my $sth_select = $dbh->prepare(
"SELECT DATE_FORMAT(timestamp, '%m/%d/%y') FROM foo"
);
$sth_select->execute() || die "Unable to execute query: $dbh->errstr";
if (my $ref = $sth_select->fetchrow_hashref()) {
print $q->header;
print " TIME: $ref->{timestamp}";
exit;
}
结果
TIME:
它根本不打印格式化的时间,它是空白的!
当我尝试打印时间戳时,它不会打印任何内容,但如果我要删除 DATA_FORMAT 并只是简单地执行 SELECT timestamp FROM foo ,那么它会打印时间戳很好,虽然没有格式化。有人可以就这个问题提供他们的见解吗?
For the past couple of hours I've been trying to format a MySQL timestamp using DATE_FORMAT
and it doesn't do anything!
Perl Code:
use CGI;
use DBI;
my $q = new CGI;
# Database connection goes here
my $sth_select = $dbh->prepare(
"SELECT DATE_FORMAT(timestamp, '%m/%d/%y') FROM foo"
);
$sth_select->execute() || die "Unable to execute query: $dbh->errstr";
if (my $ref = $sth_select->fetchrow_hashref()) {
print $q->header;
print " TIME: $ref->{timestamp}";
exit;
}
Results
TIME:
It doesn't print the formatted time at all, it is blank!
When I attempt to print the timestamp it doesn't print anything, but if I were to remove DATA_FORMAT
and just simply do a SELECT timestamp FROM foo
, then it prints the timestamp just fine, albeit not formatted though. Can somebody provide their insight on this matter, please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
返回的散列具有数据库提供的键列标题。当使用这样的函数时,列标题实际上是“DATE_FORMAT(timestamp, '%m/%d/%y')”。
尝试将您的 SQL 修改为:
The hash returned has as keys column headers as provided by the database. When using a function like that, the column header is actually "DATE_FORMAT(timestamp, '%m/%d/%y')".
Try modifying your SQL to be: