MySql和PHP之间的日期/时间差异? [英] Date/Time differences between MySql and PHP?

查看:73
本文介绍了MySql和PHP之间的日期/时间差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这张桌子

Name                       Birth_Date            Register_Date
---------------------------------------------------------------
Ali                       1990-03-22             2010-03-1 15:1:42
Ali1                      1991-07-18             2010-03-2 12:44:2

当我插入这些值时,我将 Birth_Date 插入为字符串,例如 1990-03-22,而我在 Register_Date 中使用了 NOW()。

When I inserted these values, I inserted the Birth_Date as a String such as '1990-03-22', and I used 'NOW()' for Register_Date.

NOW()将生成当前的 datetime 根据MySql Server。

NOW() will generate the current datetime according to the MySql Server.

现在,当我尝试获取当前日期和 Register_Date之间的时间时(自他注册以来经过的时间),我使用以下方法:

Now when I try to get the time between the current date and the Register_Date (Time passed since he registered), I use the following:

SELECT YEAR(CURDATE())-YEAR(register_date) ...

在PHP中,如果我想这样做,我想必须获取当前日期: date('Ymd H:i :s');

In PHP, if I wanted to do that, I suppose I have to get the current date: date('Y-m-d H:i:s');

我的问题是,通过MySql计算日期差(日期与今天之间)之间是否存在差异?通过PHP?

My question is, is there a difference between calculating the date difference (between a date and today) via MySql or via PHP?

当前,在我的本地主机(XAMPP)上, CURDATE() date(..)会生成相同的日期,但是当我的网站上线时会为其他用户生成相同的日期吗?

Currently, on my localhost (XAMPP), CURDATE() and date(..) generates the same date, but will it generate the same date for other users when my website goes online?

推荐答案

如果您的mysql和PHP服务器都在同一时区运行,并且它们的时钟正确同步,则不会有问题。

If both your mysql and PHP server are operating on the same timezone and have their clocks properly synchronized, you wont have an issue.

这篇关于MySql和PHP之间的日期/时间差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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