Class Month
- Namespace
- YndigoBlue.Velocity.Functions
- Assembly
- YndigoBlue.Velocity.dll
Represents the MONTH date extraction function that returns the month component of a date.
public class Month : Function, ICheckItem, IDefaultItem, IFilterItem, IElement
- Inheritance
-
Month
- Implements
Remarks
The MONTH function extracts the month as an integer (1-12) from a date or datetime value. For example, MONTH('2024-03-15') returns 3. This is useful for grouping data by month, seasonal analysis, or filtering records by specific months.
Examples
Extract the month number from each order date:
var schema = manager.LoadSchema("sales");
var orders = schema["orders"];
var query = new Query()
.Select([ orders["id"], new Expression("order_month", new Month(orders["order_date"])) ])
.From(orders);
var results = manager.Retrieve(query);
Use the typed Column constructor when working with a pre-resolved column variable:
var schema = manager.LoadSchema("sales");
var orders = schema["orders"];
Column orderDateColumn = orders["order_date"];
var query = new Query()
.Select([ orders["id"], new Expression("order_month", new Month(orderDateColumn)) ])
.From(orders);
var results = manager.Retrieve(query);
Extract the month from a hard-coded date literal using DateTime, DateOnly, or DateTimeOffset:
// DateTime literal
var monthFromDateTime = new Month(new DateTime(2024, 3, 15));
// DateOnly literal
var monthFromDateOnly = new Month(new DateOnly(2024, 3, 15));
// DateTimeOffset literal
var monthFromOffset = new Month(new DateTimeOffset(2024, 3, 15, 0, 0, 0, TimeSpan.Zero));
Constructors
- Month(IEnumerable<IElement>)
Initializes a new instance of MONTH for multiple elements.
- Month(DateOnly)
Initializes a new instance of MONTH for a DateOnly literal value.
- Month(DateTime)
Initializes a new instance of MONTH for a DateTime literal value.
- Month(DateTimeOffset)
Initializes a new instance of MONTH for a DateTimeOffset literal value.
- Month(IElement)
Initializes a new instance of MONTH for a single element.
- Month(Column)
Initializes a new instance of MONTH for a column.