day — Extract calendar-day numbers or weekday names from datetime and legacy date inputs.
day supports dayofmonth, dayofweek, iso-dayofweek, dayofyear, name, and shortname for datetime inputs. Numeric modes return host doubles with matching shape; name modes return same-shaped cell arrays of character vectors. Legacy serial-number and text inputs are retained for compatibility and return day-of-month values.
Syntax
X = day(t)
X = day(t, dayType)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
value | Any | Yes | — | Datetime input. |
t | Any | Yes | — | Datetime, legacy serial date number, or date text. |
dayType | StringScalar | Yes | — | dayofmonth, dayofweek, iso-dayofweek, dayofyear, name, or shortname. |
Returns
| Name | Type | Description |
|---|---|---|
X | Any | Numeric scalar/tensor result. |
out | Any | Method result. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:datetime:InvalidArgument | Arguments or option grammar do not match supported datetime forms. | datetime: invalid argument |
RunMat:datetime:InvalidInput | Input values cannot be parsed/converted/broadcast to a valid datetime result. | datetime: invalid input |
RunMat:datetime:Internal | Internal datetime state or indexing/evaluation failed unexpectedly. | datetime: internal operation failed |
How day works
day(t)defaults to day-of-month.day(t, dayType)acceptsdayofmonth,dayofweekwith Sunday equal to 1,iso-dayofweekwith Monday equal to 1,dayofyear,name, andshortname.- Numeric output is double and preserves input shape. Name output is a same-shaped cell array of character vectors; NaT yields NaN numerically and an empty character vector in name modes.
- Legacy serial date numbers accept single, double, and all eight integer classes. Legacy date text may provide its datestr-style input format as the second argument; in that dialect lowercase
mmdenotes month, as inday("2021/28/09", "yyyy/dd/mm"). - Logical and resident numeric legacy inputs are not part of the public compatibility surface. They are rejected in MATLAB-compatible mode before any resident provider access and are available only through declared RunMat extensions.
Does RunMat run day on the GPU?
day does not dispatch GPU kernels; it extracts the day component from CPU-side datetime objects.
GPU memory and residency
No. day reads datetime objects on the CPU and returns ordinary host-side numeric arrays.
Examples
Extract the day from a scalar datetime
t = datetime(2024, 4, 9, 13, 30, 0);
d = day(t)Expected output:
d = 9Extract days from a datetime array
t = datetime([2024 2025], [1 6], [15 20]);
d = day(t)Expected output:
d =
15 20Extract ISO weekday numbers
t = datetime(2024, 4, 9);
d = day(t, 'iso-dayofweek')Expected output:
d = 2Extract short weekday names
n = day(datetime(2024, 4, 9), 'shortname')Expected output:
n = {'Tue'}Using day with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how day changes the result.
Run a small day example, explain the result, then change one input and compare the output.
FAQ
What day does day return?⌄
It returns day-of-month by default. The optional day type selects weekday numbering, ISO weekday numbering, day-of-year, or full and abbreviated weekday names.
Does day preserve the input shape?⌄
Yes. The numeric output has the same size as the input datetime array.
Does day run on the GPU?⌄
No. datetime values are host-side objects, so day executes on the CPU.
Related Datetime functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how day is executed, line by line, in Rust.
- View the source for day in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.