gpt4 book ai didi

mysql - 如何在表中使用函数

转载 作者:行者123 更新时间:2023-11-29 01:55:05 24 4
gpt4 key购买 nike

我创建了一个表,其中我使用了时间戳列,它告诉记录在那个时间和日期更新。

create table age_info (age tinyint not null,created_on timestamp not null );

但我想像这样更改显示。
select date_format(Now() ,'%W, %e %M %Y @ %r');

Tuesday, 31 July 2015 @ 02:32:16 PM

但是不知道怎么做。当我插入值时

insert into age_info(age) values (19);

在表中是这样显示的。

age      created_on
19 2015-07-31 18:55:01

我不知道如何将此函数 date_format 与时间戳列一起使用以显示这种格式。

最佳答案

我想这会帮助你解决问题

SELECT DATE_FORMAT(`created_on` , '%W, %e %b %Y @ %r') FROM `age_info`;

插入,

 INSERT INTO `age_info` (`age`) select DATE_FORMAT(now() , '%W %e, %b %Y @ %r')created_on from age_info

注意,需要把表字段改成varchar。

关于mysql - 如何在表中使用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31265102/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com