quarter
Quarter number of input date and time
Syntax
Description
Examples
t = datetime(2013,05,31):calmonths(3):datetime(2014,05,31)
t = 1×5 datetime
31-May-2013 31-Aug-2013 30-Nov-2013 28-Feb-2014 31-May-2014
q = quarter(t)
q = 1×5
2 3 4 1 2
Input Arguments
Input date and time, specified as a datetime
array.
To support existing code that previously required Financial Toolbox™, quarter
also accepts serial date numbers
and text as inputs, but they are not recommended. For more information, see
Version
History.
Extended Capabilities
The
quarter
function fully supports tall arrays. For more information,
see Tall Arrays.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced in R2014bAlthough quarter
supports serial date number and text inputs,
datetime
values are recommended instead. The
datetime
data type provides flexible date and time formats,
storage out to nanosecond precision, and properties to account for time zones and
daylight saving time.
To convert serial date numbers or text to datetime
values, use
the datetime
function. For
example:
t = datetime(738427.656845093,"ConvertFrom","datenum"); q = quarter(t)
q = 3
There are no plans to remove support for serial date number or text inputs.
In previous releases, there were two quarter
functions: one
in MATLAB® that accepted datetime
values, and one in
Financial Toolbox that accepted serial date numbers or text values. As of R2022a, you
can call quarter
without Financial Toolbox. When you call quarter
from MATLAB, it accepts all previous input types.
For example, you can make these calls with a serial date number and text from MATLAB:
q = quarter(738427.656845093)
q = 3
q = quarter("28-Sep-2021")
q = 3
Nonstandard Calendar and Date Format
In addition, quarter
accepts two other inputs when the first
input is not a datetime
array. You can specify a second input
(month1
) for the first month of the financial calendar you
are using. You can also specify a third input (F
) for the date
format.
q = quarter(t,month1) q = quarter(t,month1,F)
To determine the quarter of t
with respect to a different
financial calendar, specify month1
as an integer between
1
–12
(corresponding to the months from
January to December). For example, if the fiscal year of your calendar starts on
October 1, specify month1
as 10
.
q = quarter("2021/28/09",10)
q = 4
To interpret t
using a particular date format, specify
F
using a valid date format as documented for the
datestr
function, though 'Q'
format
specifiers are not supported. For example:
q = quarter("2021/28/09",1,"yyyy/dd/mm")
q = 3
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: United States.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)