在MySQL查询中将时间戳转换为日期

编程入门 行业动态 更新时间:2024-10-27 20:30:31
本文介绍了在MySQL查询中将时间戳转换为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想将MySQL中的timestamp转换为日期.

I want to convert a timestamp in MySQL to a date.

我想将user.registration字段的格式设置为yyyy-mm-dd.

I would like to format the user.registration field into the text file as a yyyy-mm-dd.

这是我的SQL:

$sql = requestSQL("SELECT user.email, info.name, FROM_UNIXTIME(user.registration), info.news FROM user, info WHERE user.id = info.id ", "export members");

我还尝试了日期转换:

DATE_FORMAT(user.registration, '%d/%m/%Y') DATE(user.registration)

我在写文本文件之前回显结果,我得到了:

I echo the result before to write the text file and I get :

email1; name1; DATE_FORMAT(user.registration,'%d/%m/%Y'); news1

email1;name1;DATE_FORMAT(user.registration, '%d/%m/%Y');news1

email2; name2; news2

email2;name2;news2

如何将该字段转换为日期?

How can I convert that field to date?

推荐答案

DATE_FORMAT(FROM_UNIXTIME(`user.registration`), '%e %b %Y') AS 'date_formatted'

更多推荐

在MySQL查询中将时间戳转换为日期

本文发布于:2023-10-19 07:18:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1506774.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   中将   日期   时间   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!