gpt4 book ai didi

php - 在 mySQL 中将日期值转换为会计/纳税年度

转载 作者:行者123 更新时间:2023-11-28 23:20:57 25 4
gpt4 key购买 nike

有没有办法将 Date 格式值转换为 taxYear/Accounting year 格式,以便它们可以分组?

EG 会计/纳税年度为 4 月 1 日至 3 月 31 日:

Date_Col         Tax_Year/AccountingYear
2016-01-01 === 15/16
2015-05-25 === 15/16
2015-03-05 === 14/15

是否可以在 mysql 查询或 php 函数中完成相同的工作?

最佳答案

您可以通过减去 3 个月/加 9 个月并使用类似的东西来进行转换:

select concat(date_format(date_sub(date_col, interval 3 month), '%y'),
'/',
date_format(date_add(date_col, interval 9 month), '%y')
) as tax_year

编辑:

你可以试试这个:

select concat(year(date_sub(date_col, interval 3 month),
'/',
year(date_add(date_col, interval 9 month)
) as tax_year

此版本应返回“2016/2017”。无论如何,我更喜欢 4 位数的年份。

关于php - 在 mySQL 中将日期值转换为会计/纳税年度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41612534/

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