How to know the current quarter with date?

2019-03-03 23:05发布

Is it possible to know the current quarter using Linux command line?

I didn't find a way to do it within the date man page.

2条回答
冷血范
2楼-- · 2019-03-03 23:53

The dates corresponding to the start and end of a fiscal quarter vary by country, as well by the nature of the entity doing the fiscal reporting (corporate/personal/government/other...); some companies also have alternate schedules. As such, there is no standard API for this. You will have to get the current month and date and compare it to the appropriate quarter start/end dates for the country and entity of interest. You can find the dates for some countries in wikipedia.

查看更多
干净又极端
3楼-- · 2019-03-03 23:54

There is now the %q format to show this information.

From the coreutils-8.26 release log from November 30, 2016:

New Features
...
date now accepts the %q format to output the quarter of the year.

And yes it works!

$ date "+%q"
4
$ date "+%Y%q"
20164
查看更多
登录 后发表回答