year — Extract year numbers from datetime values.
year extracts the calendar year from a datetime scalar or array and returns the result as doubles with the same shape as the input.
How year works
year(t)accepts datetime scalars and datetime arrays.- The output shape matches the input shape.
- The returned values are numeric doubles, even when the years are mathematically integers.
- Passing a non-datetime value raises a datetime-specific error.
How RunMat runs year on the GPU
year does not dispatch GPU kernels. If the datetime was produced from gathered numeric data, the result still remains a CPU numeric array.
GPU memory and residency
No. year reads datetime objects on the CPU and returns ordinary host-side numeric arrays.
Examples
Extract the year from a scalar datetime
t = datetime(2024, 4, 9, 13, 30, 0);
y = year(t)Expected output:
y = 2024Extract years from a datetime array
t = datetime([2024 2025], [1 6], [15 20]);
y = year(t)Expected output:
y =
2024 2025FAQ
Does year preserve the input shape?⌄
Yes. A scalar datetime returns a scalar double, and datetime arrays return numeric arrays of the same size.
Does year return integers?⌄
It returns MATLAB-style doubles whose values are whole-number years.
Does year run on the GPU?⌄
No. datetime values are host-side objects, so year executes on the CPU.
Related Datetime functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how year works, line by line, in Rust.
- View year.rs on GitHub
- Learn how the 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 — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.