gpt4 book ai didi

mysql - 更改 SQL 中的日期

转载 作者:行者123 更新时间:2023-11-29 13:43:49 26 4
gpt4 key购买 nike

考虑一个表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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com