Skip to main content

SalDateTime

Namespace: PPJ.Runtime

Assembly: PPJ.Runtime.50 (5.0.0.0)

Represents a date and time with a separate SAL null state.

public struct SalDateTime : 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

Instance member SalDateTime(x)

Wraps a DateTime and establishes its SAL null state.

NameTypeDescription
xDateTimeThe date and time to wrap.

DateTime.MinValue is treated as null only when TreatMinValueAsNull is enabled.

Instance member SalDateTime(year, month, day)

Constructs a date from calendar and time components, normalizing overflowing components when possible.

NameTypeDescription
yearInt32The base calendar year.
monthInt32The month number, normally 1 through 12.
dayInt32The 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.

Instance member SalDateTime(year, month, day, hour, minute, second)

Constructs a date from calendar and time components, normalizing overflowing components when possible.

NameTypeDescription
yearInt32The base calendar year.
monthInt32The month number, normally 1 through 12.
dayInt32The day number, normally within the selected month.
hourInt32The hour component.
minuteInt32The minute component.
secondInt32The 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.

Instance member SalDateTime(year, month, day, hour, minute, second, milliseconds)

Constructs a date from calendar and time components, normalizing overflowing components when possible.

NameTypeDescription
yearInt32The base calendar year.
monthInt32The month number, normally 1 through 12.
dayInt32The day number, normally within the selected month.
hourInt32The hour component.
minuteInt32The minute component.
secondInt32The second component.
millisecondsInt32The 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

Static member Current

SalDateTime: Gets the current local date and time of the executing machine.

Instance member IsNull

Boolean: Gets whether this value represents SAL null.

Instance member Ticks

Int64: Gets the tick count of the stored date.

Static member 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.

Instance member Value

DateTime: Gets the underlying DateTime.

Methods

Instance member AddDays(days)

Adds a signed number of days to this date.

ParameterTypeDescription
daysDoubleThe number of days to add, including fractional days.

Returns: SalDateTime. The adjusted date, or SAL null if this value is null.

Throws:

Static member Compare(x, y)

Compares the underlying DateTime values.

ParameterTypeDescription
xSalDateTimeThe left date.
ySalDateTimeThe 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.

Instance member CompareTo(obj)

Compares the stored date with another date.

ParameterTypeDescription
objObjectA 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.

Instance member CompareTo(x)

Compares the stored date with another date.

ParameterTypeDescription
xSalDateTimeThe 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.

Instance member Day()

Returns the day component of this date.

Returns: SalNumber. The day (1 through 31), or -1 for SAL null.

Instance member Hour()

Returns the hour component of this date.

Returns: SalNumber. The hour (0 through 23), or -1 for SAL null.

Instance member Minute()

Returns the minute component of this date.

Returns: SalNumber. The minute (0 through 59), or -1 for SAL null.

Instance member Month()

Returns the month component of this date.

Returns: SalNumber. The month (1 through 12), or -1 for SAL null.

Instance member MonthBegin()

Returns midnight on the first day of the month.

Returns: SalDateTime. The beginning date, or SAL null when this value is null.

Instance member Quarter()

Returns the quarter component of this date.

Returns: SalNumber. The quarter (1 through 4), or -1 for SAL null.

Instance member QuarterBegin()

Returns midnight on the first day of the calendar quarter.

Returns: SalDateTime. The beginning date, or SAL null when this value is null.

Instance member Second()

Returns the second component of this date.

Returns: SalNumber. The second (0 through 59), or -1 for SAL null.

Instance member Subtract(x)

Returns the difference from another date in days.

ParameterTypeDescription
xSalDateTimeThe 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.

Instance member 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.

Instance member 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.

Instance member 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.

Instance member Year()

Returns the year component of this date.

Returns: SalNumber. The year (1 through 9999), or -1 for SAL null.

Instance member YearBegin()

Returns midnight on January 1 of the year.

Returns: SalDateTime. The beginning date, or SAL null when this value is null.

Used By

NameDescription
Sal.FileSetDateTime
Sal.FmtFormatDateTime
Sal.ReportSetDateTimeVarAssigns a SAL date/time to a report variable.
Sal.StrToDate
SalDateTime.CurrentGets the current local date and time of the executing machine.
SalDateTime.AddDaysAdds a signed number of days to this date.
SalFileHandle.SetDateTimeSets a file's last-write time using local time.
SalString.ToDateParses the string as a date/time value.
SalSafeArray.PutDateWrites a date/time element in the one-dimensional array.
SalSafeArray.PutDate2DWrites a date/time element in the two-dimensional array.
SalSafeArray.PutDateMDWrites a date/time element in the multidimensional array.
SalVariant.SetDateStores the date value.
SalDataField.DateTimeGets or sets the field value as a SAL date and time using the field formatting rules.
SalTableColumn.DateTimeGets 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