mysql 中的 getdate() [英] getdate() in mysql

查看:195
本文介绍了mysql 中的 getdate()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个系统,当某事完成时更新用户活动.我有一个变量 $userhistory='Useredited'.$info.'2010 年 7 月 14 日或 (07-14-2010);

I am creating a system which updates the user activity when something is done. I have a variable $userhistory= 'User edited '.$info.' on July 14 2010 or (07-14-2010);

我想知道如何自动获取日期.对于 sql 查询,我正在使用 NOW(),但是在像 $userhistory 这样的变量中,我如何获取日期并且它只需要这些形式中的任何一种.不随时间.另外,我正在更新数据库中的列用户历史记录,这是一个文本字段.这是正确的方法吗?我怎样才能只保存最近几次更新中的 5 个或 10 个?

I want to know how can i get the date automatically. for sql query i am using NOW(), but in a variable like $userhistory how do i get the date and it want it only in either of these forms. not along with the time. Also, I am updating the column userhistory in the database, which is a text field. Is this the correct way to do it? How can i save only 5 or 10 of the last few updates?

推荐答案

如果您在更新或将条目写入数据库时​​使用 NOW(),则存储日期(用户历史?)的列应该是 DATETIME 类型.

If you are using NOW() when you update or write an entry to the database, the column storing the date (userhistory?) should be of DATETIME type.

然后你会像往常一样运行你的 SQL :

Then you'd you'd run your SQL as normal :

SELECT field1, field2, UNIX_TIMESTAMP(userhistory) FROM table;

然后在 PHP 中,对数据库结果使用 date() 对其进行相应的格式化:

Then in PHP, use date() on the database result to format it accordingly:

// July 14 2010
date('F j Y', $row['userhistory']);
// 07-14-2010
date('m-d-Y', $row['userhistory']); ,

这篇关于mysql 中的 getdate()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆