Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQL查询帮助-DATEDIFF并将结果写入新列_Php_Mysql_Sql - Fatal编程技术网

Php MySQL查询帮助-DATEDIFF并将结果写入新列

Php MySQL查询帮助-DATEDIFF并将结果写入新列,php,mysql,sql,Php,Mysql,Sql,好吧,我有一个讨厌的问题要解决,我被难住了 我有一个MySQL表,基本上就是这样的结构 id transdate startdate enddate unit1 unit1price unit2 unit2price 1 2014-07-31 2014-10-25 2014-10-29 22 25.00 27 25.00 我需要做的是创建另一列totaldays,它计算startdate和enddate之间的天数 我该

好吧,我有一个讨厌的问题要解决,我被难住了

我有一个MySQL表,基本上就是这样的结构

id  transdate  startdate   enddate      unit1  unit1price   unit2   unit2price

1   2014-07-31   2014-10-25  2014-10-29   22     25.00        27      25.00
我需要做的是创建另一列totaldays,它计算startdate和enddate之间的天数

我该怎么做


非常感谢

您可以尝试以下方法:

SELECT datediff(enddate, startdate)...
此处的更多信息:

--创建列

alter table YourTableName
add column daysdiff int;
--使用适当的计算更新新列

update YourTableName
set daysdiff = datediff(enddate, startdate);

如果我把MySQL中的
get date difference
放在Google中,我会得到无数个计数,你尝试过什么?我知道我需要使用DATEDIFF,但是我如何循环行并将该值写入一个新列?