SalDateTime
Namespace: PPJ.Runtime
Assembly: PPJ.Runtime.50 (5.0.0.0)
Represents a date and time with a separate SAL null state.
- C#
- VB.NET
public struct SalDateTime : ValueType, IComparable, IConvertible, IFormattable, INullable, ISalType, IXmlSerializable
Public Structure SalDateTime
Implements ValueType, IComparable, IConvertible, IFormattable, INullable, ISalType, IXmlSerializable
A default-initialized value is null. Comparisons use the underlying DateTime, without comparing the null flag. Arithmetic uses days, including fractional days.
Example:
using PPJ.Runtime;
SalDateTime start = new SalDateTime(2026, 9, 19);
SalDateTime next = start + (SalNumber)1;
SalNumber elapsedDays = next - start; // 1
SalString label = start.ToString("yyyy-MM-dd");
SalDateTime missing = SalDateTime.Null;
System.DateTime? optional = missing; // null
Constructors
SalDateTime(x)
Wraps a DateTime and establishes its SAL null state.
| Name | Type | Description |
|---|---|---|
| x | DateTime | The date and time to wrap. |
DateTime.MinValue is treated as null only when TreatMinValueAsNull is enabled.
SalDateTime(year, month, day)
Constructs a date from calendar and time components, normalizing overflowing components when possible.
| Name | Type | Description |
|---|---|---|
| year | Int32 | The base calendar year. |
| month | Int32 | The month number, normally 1 through 12. |
| day | Int32 | The day number, normally within the selected month. |
If direct construction fails, the components are added as offsets from January 1 of the specified year. If normalization also fails, the result is SAL null. Omitted time components are zero.
SalDateTime(year, month, day, hour, minute, second)
Constructs a date from calendar and time components, normalizing overflowing components when possible.
| Name | Type | Description |
|---|---|---|
| year | Int32 | The base calendar year. |
| month | Int32 | The month number, normally 1 through 12. |
| day | Int32 | The day number, normally within the selected month. |
| hour | Int32 | The hour component. |
| minute | Int32 | The minute component. |
| second | Int32 | The second component. |
If direct construction fails, the components are added as offsets from January 1 of the specified year. If normalization also fails, the result is SAL null. Omitted time components are zero.
SalDateTime(year, month, day, hour, minute, second, milliseconds)
Constructs a date from calendar and time components, normalizing overflowing components when possible.
| Name | Type | Description |
|---|---|---|
| year | Int32 | The base calendar year. |
| month | Int32 | The month number, normally 1 through 12. |
| day | Int32 | The day number, normally within the selected month. |
| hour | Int32 | The hour component. |
| minute | Int32 | The minute component. |
| second | Int32 | The second component. |
| milliseconds | Int32 | The millisecond component. |
If direct construction fails, the components are added as offsets from January 1 of the specified year. If normalization also fails, the result is SAL null. Omitted time components are zero.
Properties
Current
SalDateTime: Gets the current local date and time of the executing machine.
IsNull
Boolean: Gets whether this value represents SAL null.
Ticks
Int64: Gets the tick count of the stored date.
TreatMinValueAsNull
Boolean: Gets or sets whether newly wrapped DateTime.MinValue values represent SAL null.
The initial setting is false. Changing it does not alter the null flags of values already constructed.
Value
DateTime: Gets the underlying DateTime.
Methods
AddDays(days)
Adds a signed number of days to this date.
| Parameter | Type | Description |
|---|---|---|
| days | Double | The number of days to add, including fractional days. |
Returns: SalDateTime. The adjusted date, or SAL null if this value is null.
Throws:
- ArgumentOutOfRangeException The result is outside the DateTime range.
Compare(x, y)
Compares the underlying DateTime values.
| Parameter | Type | Description |
|---|---|---|
| x | SalDateTime | The left date. |
| y | SalDateTime | The right date. |
Returns: Int32. A negative value if x precedes y, zero if their dates are equal, or a positive value if x follows y.
The SAL null flags do not affect ordering.
CompareTo(obj)
Compares the stored date with another date.
| Parameter | Type | Description |
|---|---|---|
| obj | Object | A SalDateTime, DateTime, or null. |
Returns: Int32. A negative value if this date precedes the argument, zero if equal, or a positive value if it follows.
The SAL null flag is ignored. A null argument sorts before this value; other unsupported object types cause ArgumentException.
CompareTo(x)
Compares the stored date with another date.
| Parameter | Type | Description |
|---|---|---|
| x | SalDateTime | The date to compare with this value. |
Returns: Int32. A negative value if this date precedes the argument, zero if equal, or a positive value if it follows.
The SAL null flag is ignored.
Day()
Returns the day component of this date.
Returns: SalNumber. The day (1 through 31), or -1 for SAL null.
Hour()
Returns the hour component of this date.
Returns: SalNumber. The hour (0 through 23), or -1 for SAL null.
Minute()
Returns the minute component of this date.
Returns: SalNumber. The minute (0 through 59), or -1 for SAL null.
Month()
Returns the month component of this date.
Returns: SalNumber. The month (1 through 12), or -1 for SAL null.
MonthBegin()
Returns midnight on the first day of the month.
Returns: SalDateTime. The beginning date, or SAL null when this value is null.
Quarter()
Returns the quarter component of this date.
Returns: SalNumber. The quarter (1 through 4), or -1 for SAL null.
QuarterBegin()
Returns midnight on the first day of the calendar quarter.
Returns: SalDateTime. The beginning date, or SAL null when this value is null.
Second()
Returns the second component of this date.
Returns: SalNumber. The second (0 through 59), or -1 for SAL null.
Subtract(x)
Returns the difference from another date in days.
| Parameter | Type | Description |
|---|---|---|
| x | SalDateTime | The date to subtract from this value. |
Returns: Double. The signed difference, including fractional days; zero if either value is null.
Example:
using PPJ.Runtime;
SalDateTime start = new SalDateTime(2026, 1, 1, 6, 0, 0);
SalDateTime end = new SalDateTime(2026, 1, 2, 18, 0, 0);
double days = end.Subtract(start); // 1.5
double reverse = start.Subtract(end); // -1.5
double missing = end.Subtract(SalDateTime.Null); // 0, not an unknown duration.
// Check IsNull before subtraction when missing dates must remain distinguishable.
ToDateTime()
Returns the underlying DateTime without preserving the SAL null flag.
Returns: DateTime. The stored DateTime, including DateTime.MinValue for a default or explicitly null value.
WeekBegin()
Returns midnight on Monday of the containing week.
Returns: SalDateTime. The beginning date, or SAL null when this value is null.
The week starts on Monday regardless of culture.
Weekday()
Returns the SAL weekday number.
Returns: SalNumber. Zero for Saturday, 1 for Sunday, 2 for Monday, through 6 for Friday; or -1 for SAL null.
Year()
Returns the year component of this date.
Returns: SalNumber. The year (1 through 9999), or -1 for SAL null.
YearBegin()
Returns midnight on January 1 of the year.
Returns: SalDateTime. The beginning date, or SAL null when this value is null.
Used By
| Name | Description |
|---|---|
| Sal.FileSetDateTime | |
| Sal.FmtFormatDateTime | |
| Sal.ReportSetDateTimeVar | Assigns a SAL date/time to a report variable. |
| Sal.StrToDate | |
| SalDateTime.Current | Gets the current local date and time of the executing machine. |
| SalDateTime.AddDays | Adds a signed number of days to this date. |
| SalFileHandle.SetDateTime | Sets a file's last-write time using local time. |
| SalString.ToDate | Parses the string as a date/time value. |
| SalSafeArray.PutDate | Writes a date/time element in the one-dimensional array. |
| SalSafeArray.PutDate2D | Writes a date/time element in the two-dimensional array. |
| SalSafeArray.PutDateMD | Writes a date/time element in the multidimensional array. |
| SalVariant.SetDate | Stores the date value. |
| SalDataField.DateTime | Gets or sets the field value as a SAL date and time using the field formatting rules. |
| SalTableColumn.DateTime | Gets or sets the datetime value of this column in the table context row. |
| Vis.ArrayFillDateTime | |
| Vis.ArrayFindDateTime | |
| Vis.FileSetDateTime | |
| Vis.TblFindDateTime | |
| VisCalendar.IsSelectedDate | |
| VisCalendar.SetFocusDate | |
| VisCalendar.SelectDate | |
| VisCalendar.SetSpecialDate | |
| VisCalendar.IsSpecialDate | |
| VisCalendarDropDown.Value | |
| XSal.ZipCreateFile | |
| XSal.StrFormatDateTime | |
| XSal.StrFormatDateTimeX |