mysql - 更改 SQL 中的日期

标签 mysql sql date

考虑一个表DateDetails,其中有一列 effectiveDate。 我想编写一个更新查询:

  if effectiveDate > "first day of the month" then
         ->set it to "first day of the month"

类似于:

update DateDetails
set effectiveDate = (start of the month)
where effectiveDate > (start of the month)

effectiveDate 的类型为 DATE。日、月、年也可以是任意:12-JAN-2013 或 24-DEC-2056
我该如何写这个?

最佳答案

update DateDetails
set effectiveDate = DATE_FORMAT(start_date ,'01-%b-%Y')
where effectiveDate > start_date;

将所有日期更改为生效日期当月的第一天

update DateDetails
set effectiveDate = DATE_FORMAT(effectiveDate ,'01-%b-%Y');

关于mysql - 更改 SQL 中的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17724959/

相关文章:

java - Java判断两个日期是否在同一天

python - 如何在 Pandas 中显示正确的日期世纪?

php - PHP 脚本中的特殊字符停止执行

mysql优化数据内容: multi column or simple column hash data

python - SQL中的x'0a'是什么意思?

php - Mysql通过VARCHAR字段插入订单号

mysql - 是否可以仅导出 mysql workbench 中的函数

c++ - qt数据库fedora的mysql驱动

sql - 派生查询抛出错误 ORA-00604 : error occurred at recursive SQL level 1

Python主控