How to know the current quarter with date? - linux

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.

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.

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

Related

Excel formula to determine shipping date

Due to production and shipping issues my job has created a report that has the customer's need by date and if a product has been completed or not. If an order is complete we need to determine when it will ship out and arrive to the customer. We have a set shipping schedule and orders get shipped on the truck right before the need by date. For example our truck leaves on Monday and Friday every week so if an order is complete and the need by date is on a Wednesday it will ship on Monday so any order with a need by date from Tuesday to Friday gets shipped the Monday before and any need by date from Saturday to Monday gets shipped on Friday. Now my questions is, is there a way to have a date range yield it's shipping date? Example when I'm writing this it's 5/11/2022 so if I have completed orders with need by dates of 5/12 and 5/15 all of which should be on the 5/13 truck could I use a formula to fill in the shipping date for those need by dates? We've been doing it manually and although determining the dates isn't difficult it's time consuming when each report has over 3000 lines and there is a report for each customer. If it's not possible then we won't have a choice but I would like to hope so. Please help.
The third column is just to show that the ship dates are on the correct day. It looks different because the dates are Australian (DD/MM/YYYY) rather than American (MM/DD/YYYY), but that shouldn't matter for the function to work.
The function in the Ship Date column:
=IF(OR(TEXT(A8,"dddd")="Tuesday",TEXT(A8,"dddd")="Wednesday",TEXT(A8,"dddd")="Thursday",TEXT(A8,"dddd")="Friday"),A8-WEEKDAY(A8,3),A8-WEEKDAY(A8+2,2))
Need By Date (including header) = A7:A20
Ship Date (including header) = B7:B20
Explanation
TEXT(value, format_text): this is used to convert the date (DD/MM/YYYY) to the long day (e.g. Monday)
Breakdown
IF the day is Tues, Wed, Thurs, or Fri
THEN return the date of that weeks Monday
ELSE return the date of that weeks Friday

Finding out the difference between two quarter periods in Excel

Need to find out the difference between two quarter periods.
Data as shown below:
Any plan sold year on same quarter (Let's say Oct, Nov or Dec) and the Check Month quarter ( Let's say May, June, July) would have the same difference in the quarter periods.
Need the formula to catch the difference between two quarter periods.
Eg:
Plan Sold Year: 2013 Dec
Check Year: 2018 Feb
Difference in periods: 18 periods (including 2013 quarter period as well)
One way of tackling your question is to work out the Plan Sale Quarter Start Date and Check Quarter End Date, then do a calculation between the two dates to work out the periods (full quarters) in between.
In my solution I used two helper columns being PSQStart and CQEnd that represent the two critical dates mentioned above.
Formulas are:
PSQStart =DATE($A2,FLOOR(MONTH(DATEVALUE("1/"&$B2&"/"&$A2))-1,3)+1,1)
CQEnd =DATE(D2,FLOOR(MONTH(DATEVALUE("1/"&$E2&"/"&$D2))+2,3),30)
Periods =ROUNDDOWN((H2-G2)/90,0)
Drag all three formulas down to apply to all rows.
You can choose to combine the first two formulas into the third one but it will make the formula too long to be easily interpreted and/or edited for future needs.
Here are the main functions used in my solution:
DATE() convert yyyy,mm,dd into a valid date/numerical value for calculations;
DATEVALUE() convert text date dd/mmm/yyyy into a valid date/numerical value for calculations;
FLOOR() work out the start/end month for a given month;
ROUNDDOWN() calculate the number of periods.
Cheers :)

Calculate month or quarter of a given date for ISOWEEK calendar

In Excel there is a ISOWEEK() function that returns the WEEK of a given date (according to the ISOWEEK system). I wonder how to create similar functions for the MONTH and for the QUARTER (i.e. given a certain data, what is its ISO month or its ISO quarter)? Thanks.
I have tried myself to build the functions but by looking at historical data I cant see a regular pattern, for instance depending on the year, some months have 4 or 5 weeks, but this change seems not following a regular pattern. Also the duration of the quarter for the ISOWEEK system is not so clear to me, shall I assume that the quarter is always 13 full weeks in the case of years with 52 weeks, and with 13+13+13+14 weeks when the year has 53 weeks?.
There are some functions to calculate the quarter as described here: https://www.extendoffice.com/documents/excel/2475-excel-convert-date-to-fiscal-year-or-quarter-or-month.html, for instance
Quarter for a given date:
=CHOOSE(MONTH(A6),3,3,3,4,4,4,1,1,1,2,2,2)
Fiscal month for a given date:
=CHOOSE(MONTH(A6),7,8,9,10,11,12,1,2,3,4,5,6)
However, seems that they don't completely match the ISOWEEK system (for more info about ISOWEEK: https://en.wikipedia.org/wiki/ISO_week_date ).
ISOMONTH should return the given month of a date, for instance ISOMONTH (15/01/2019) should return 1. In a similar way, ISOQUARTER (15/01/2019) should return 1.

Dialogflow obtaining wrong dates for prebuilt date entities

Is there a way to change how Dialogflow automatically calculates the date meant by a text identified as a pre-built entity like "sys.date" or "sys.date-period"?
Or, is there a way to create your own entity for dates, and specify how it determines the specific day?
Depending on the day of the week, texts like "on Friday" are actually interpreted as the closest Friday to come in the future, instead of the most recent Friday that has already passed.
If you are using #sys.date entity then you can set the value as date.recent. It will always try to convert the phrase into most recent date.
For example, if you say on monday, it will give you date of recent monday.
Note that the date.recent option is available only for #sys.date not for #sys.date-time or #sys.date-period.
EDIT:
You need to select $date.recent from the options available
As you can see in the example screenshot below, tuesday is converted to most recent tuesday rather than upcoming tuesday.
Hope it helps.

Extract year from cognos report expression

I want to extract current year, last year in report expression field but am not able to get it.
date2timestamp(Today()) and Today()
This works fine to get date
_add_years(date2timestamp(Today()),1) and extract("year",Today())
but this shows error.
I wanted to show 2016, 2015 dynamically in my report as heading of cross-tab node.
If you use layout calculation try
substring(date2string(Today()),1,4)
for current year. And
string2int32(substring(date2string(Today()),1,4)) - 1
for previous year.
for current year:
extract('year', date2timestamp(today()))
for prior year:
extract('year', _add_years(date2timestamp(today()), -1))
This will give you an integer value that you can format using the normal Data Format options in the date item properties, for example to remove the thousands comma if desired.
Make a query with two data items.
For the previous year, one data item will have:
extract (year, _add_years(current_date, -1))
And for the current year:
extract (year, current_date).

Resources