Table of Contents

Class DateTimeAddTime

Namespace
YndigoBlue.Velocity.Functions
Assembly
YndigoBlue.Velocity.dll

Represents a function that adds a Time-of-day value to a DateTime as a duration from midnight, returning a new DateTime.

public class DateTimeAddTime : Function, ICheckItem, IDefaultItem, IFilterItem, IElement
Inheritance
DateTimeAddTime
Implements

Remarks

DateTimeAddTime(datetime, time) → datetime shifted by the time duration.

The time argument is treated as a duration rather than an absolute clock time: a value of 02:30:00 adds two hours and thirty minutes to the datetime regardless of its existing time component.

Both arguments may be column references or literal values. Databases that natively support adding time to a timestamp (PostgreSQL, Oracle, Teradata) emit simple addition. Others convert the time to seconds and apply the equivalent arithmetic.

Examples

Combine a date column and a time column into a single datetime value:

var schema = manager.LoadSchema("scheduling");
var appointments = schema["appointments"];

var query = new Query()
    .Select([ appointments["id"], new Expression("starts_at", new DateTimeAddTime(appointments["appt_date"], appointments["appt_time"])) ])
    .From(appointments);

var results = manager.Retrieve(query);

Use the column + TimeOnly constructor to add a fixed time-of-day offset to each datetime:

var schema = manager.LoadSchema("scheduling");
var appointments = schema["appointments"];
Column apptDateColumn = appointments["appt_date"];

// Add 08:30:00 (8.5 hours) to each appointment date
var startTime = new TimeOnly(8, 30, 0);

var query = new Query()
    .Select([ appointments["id"], new Expression("starts_at", new DateTimeAddTime(apptDateColumn, startTime)) ])
    .From(appointments);

var results = manager.Retrieve(query);

Use the DateTime + TimeOnly constructor to add a fixed time duration to a literal datetime:

var baseDate = new DateTime(2024, 6, 1);
var shift = new TimeOnly(14, 0, 0);   // 14:00 = 14 hours

// Returns 2024-06-01 14:00:00
var expr = new DateTimeAddTime(baseDate, shift);

Constructors

DateTimeAddTime(DateTime, TimeOnly)

Initializes a new instance of DateTimeAddTime with a DateTime literal and a TimeOnly literal.

DateTimeAddTime(DateTime, Column)

Initializes a new instance of DateTimeAddTime with a DateTime literal and a time column.

DateTimeAddTime(IElement, IElement)

Initializes a new instance of DateTimeAddTime.

DateTimeAddTime(Column, TimeOnly)

Initializes a new instance of DateTimeAddTime with a DateTime column and a TimeOnly literal.

DateTimeAddTime(Column, Column)

Initializes a new instance of DateTimeAddTime with both arguments as columns.