当前日期和日期字段之间的天数
问题描述:
如果有人可以帮助,我就会遇到这个问题.
表(table1)
中有一个字段(date)
,它是格式为3/31/1988 (M/D/y)
的日期,我需要定义自该日期以来已经过了多少天.
I have this problem if anyone can help.
There is a field (date)
in my table (table1)
that is a date in the format 3/31/1988 (M/D/y)
, and my necessity is to define how many days have passed since that date.
我试图给出此指示
SELECT DATEDIFF(CURDATE(), date) AS days
FROM table1
但是它会返回'null',我认为这是因为两种日期格式不同(CURDATE()是YMD .....
But it gives back 'null' and I think this happens because the two date formats are different (CURDATE() is YMD.....
对吗?谁能帮我? 预先谢谢你
Is it correct? can anyone help me? Thank you in advance
答
You can use STR_TO_DATE()
:
SELECT DATEDIFF(CURDATE(),STR_TO_DATE(date, '%m/%d/%Y')) AS days
FROM table1