RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.1, Nov 17, 2026 ·

RunMat® is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • dateshift

dateshift — Shift datetime values to calendar boundaries or weekday occurrences.

dateshift implements the public start, end, and day-of-week forms with singular calendar units and optional current, next, previous, nearest, or integer occurrence rules. Week calculations begin on Sunday. Weekday indices and integer rules are read from authoritative integer storage before calendar evaluation.

Syntax

out = dateshift(t, boundary, unit, rule)
out = dateshift(t, 'dayofweek', weekday, rule)

Inputs

t
Type
Any
Required
Yes
Description
Host datetime value; numeric serials and relative text are not converted.
boundary
Type
StringScalar
Required
Yes
Description
'start' or 'end'.
unit
Type
StringScalar
Required
Yes
Description
Singular year, quarter, month, week, day, hour, minute, or second.
rule
Type
Any
Required
No
Default
'current'
Description
current, next, previous, nearest, or an exact integer scalar/array occurrence offset.
t
Type
Any
Required
Yes
Description
Host datetime scalar or array.
boundary
Type
StringScalar
Required
Yes
Default
'dayofweek'
Description
Day-target selection.
weekday
Type
Any
Required
Yes
Description
A scalar weekday name, weekday/weekend group, or exact numeric indices 1..7.
rule
Type
Any
Required
No
Default
'next'
Description
current, next, previous, nearest, or exact integer occurrence controls; scalar or same size.
NameTypeRequiredDefaultDescription
tAnyYes—Host datetime value; numeric serials and relative text are not converted.
boundaryStringScalarYes—'start' or 'end'.
unitStringScalarYes—Singular year, quarter, month, week, day, hour, minute, or second.
ruleAnyNo'current'current, next, previous, nearest, or an exact integer scalar/array occurrence offset.
tAnyYes—Host datetime scalar or array.
boundaryStringScalarYes'dayofweek'Day-target selection.
weekdayAnyYes—A scalar weekday name, weekday/weekend group, or exact numeric indices 1..7.
ruleAnyNo'next'current, next, previous, nearest, or exact integer occurrence controls; scalar or same size.

Returns

out
Type
Any
Description
Host datetime object, preserving input Format and exact non-scalar shape under scalar expansion, including empty geometry.
NameTypeDescription
outAnyHost datetime object, preserving input Format and exact non-scalar shape under scalar expansion, including empty geometry.

Errors

RunMat:datetime:InvalidInput
When
Input values cannot be parsed, converted, or broadcast to a valid datetime result.
Message
datetime: invalid input
RunMat:datetime:InvalidArgument
When
Arguments or option grammar do not match supported datetime forms.
Message
datetime: invalid argument
RunMat:dateshift:TooManyOutputs
When
More than one output is requested.
Message
dateshift: too many output arguments
IdentifierWhenMessage
RunMat:datetime:InvalidInputInput values cannot be parsed, converted, or broadcast to a valid datetime result.datetime: invalid input
RunMat:datetime:InvalidArgumentArguments or option grammar do not match supported datetime forms.datetime: invalid argument
RunMat:dateshift:TooManyOutputsMore than one output is requested.dateshift: too many output arguments

Behavior

dateshift(t, 'start', unit) and dateshift(t, 'end', unit) default to the current unit. Supported singular units are year, quarter, month, week, day, hour, minute, and second.

The end of a year, quarter, month, or week is midnight at the beginning of its last day. The end of a day, hour, minute, or second is exactly the start of the next unit.

dateshift(t, 'dayofweek', dow) accepts weekday names or numeric indices from 1 for Sunday through 7 for Saturday. weekday and weekend select the corresponding day groups.

Rules can be current, next, previous, nearest, or integer scalar/arrays. Datetime, weekday, and rule arrays must have matching sizes or be scalar; scalar expansion preserves the non-scalar input shape.

Plural unit aliases, nearest as a boundary token, and a custom week-start argument are rejected because they are not part of this public contract.

There is no resident datetime output. Resident arguments are accepted only through the declared RunMat extension and are gathered to a host result.

Placement and effects

dateshift operates on host datetime objects. Resident arguments are compatibility-gated before provider access.

No. Inputs and outputs are host datetime objects. A compatibility-gated resident input is gathered before calendar evaluation.

No GPU kernel is dispatched. MATLAB-compatible mode rejects resident arguments before provider access; RunMat extension mode gathers them and returns a host object.

This pure host operation reads stored datetime serials, not Clock. It may throw or suspend at admitted provider gathers and cooperative checkpoints. Resident controls follow the declared datetime input extension; terminal provider and cancellation errors retain their control-flow authority. There is no device result, GPU kernel, fusion route, or distributed support. Portable Runtime declarations are not backend execution evidence.

Syntax and argument roles

out = dateshift(t, boundary, unit, rule)

out = dateshift(t, 'dayofweek', weekday, rule)

t must be a datetime object, not relative text or a numeric serial. boundary and calendar unit are scalar text. Unit names are singular and case-insensitive. Day targets additionally accept sun/sunday, mon/monday, tue/tues/tuesday, wed/wednesday, thu/thur/thurs/thursday, fri/friday, and sat/saturday.

The optional rule defaults to current for start/end and next for dayofweek. Numeric weekday and rule controls accept real single/double and all eight native integer classes, with exact integer validation. Weekdays are 1..7; rules must fit int64. Day-target occurrences are additionally bounded to magnitude 200000000 before checked whole-week arithmetic.

There is exactly one output. The input Format is preserved. Scalar expansion preserves the full non-scalar shape, including empty arrays; multiple non-scalar shapes must match exactly.

Current implementation frontier

Calendar arithmetic retains the existing signed serial-date conversion, supported Chrono calendar range, leap-day handling, and binary64 serial-day precision. Nonfinite stored serial elements pass through unchanged. Absolute typed datetime operations require no ambient calendar or Clock fallback.

Empty datetime or numeric controls now preserve their full scalar-expanded empty geometry instead of being mistaken for one output element. Calendar output allocation and copied control vectors are not yet generally managed/cooperatively copied; independent MATLAB parity and complete backend qualification remain incomplete.

Finite execution frontier

Finite Managed calendar work is currently unsupported: the canonical host-allocation policy refuses before gathers, calendar scratch, or output publication. An initially unbounded call is checked again after suspension. Full managed scratch/output ownership remains an explicit implementation obligation; this safety fence is not Managed completion.

Examples

Shift to the Sunday at the start of the current week

out = dateshift(datetime(2024, 3, 14), 'start', 'week');

Shift to the next Monday occurrence

out = dateshift(datetime(2024, 3, 14), 'dayofweek', 'Monday');

Shift to the end of the current month

out = dateshift(datetime(2024, 2, 10), 'end', 'month');

Using dateshift with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how dateshift changes the result.

Run a small dateshift example, explain the result, then change one input and compare the output.

FAQ

When does a week begin?⌄

Sunday, matching the compatibility contract used by MATLAB calendar weeks.

Does end of month mean the last millisecond?⌄

No. For month, quarter, year, and week, it is midnight at the beginning of the final calendar day.

Related Datetime functions

Business Days

busdays · days252bus · daysdif · fbusdate · holidays · isbusday · lbusdate

Calendar Duration

caldays · calendarDuration · calendarDuration.eq · calendarDuration.minus · calendarDuration.ne · calendarDuration.plus · calmonths · calquarters · calweeks · calyears · datetick · iscalendarduration · isdatetime

Components

clock · day · hour · minute · month · now · second · today · year

Legacy

datenum · datestr · datevec · eomday · etime · isbetween · weekday

Construction

datetime

Operators

datetime.eq · datetime.ge · datetime.gt · datetime.le · datetime.lt · datetime.minus · datetime.ne · datetime.plus

Indexing

datetime.subsasgn · datetime.subsref

Duration

days · duration · duration.eq · duration.ge · duration.gt · duration.le · duration.lt · duration.minus · duration.ne · duration.plus · duration.subsasgn · duration.subsref · hours · isduration · milliseconds · minutes · seconds · years

Source you can read

Every RunMat function's source is public. Read exactly how dateshift is executed, line by line, in Rust.

  • View the source for dateshift in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • Behavior
  • Placement and effects
  • Syntax and argument roles
  • Current implementation frontier
  • Finite execution frontier
  • Examples
  • Shift to the Sunday at the start of the current week
  • Shift to the next Monday occurrence
  • Shift to the end of the current month
  • Using dateshift with coding agents
  • FAQ
  • Related Datetime functions
  • Business Days
  • Calendar Duration
  • Components
  • Legacy
  • Construction
  • Operators
  • Indexing
  • Duration
  • Source you can read
  • About RunMat