Struct NpgsqlDateTime
- Namespace
- NpgsqlTypes
- Assembly
- Npgsql.dll
A struct similar to .NET DateTime but capable of storing PostgreSQL's timestamp and timestamptz types. DateTime is capable of storing values from year 1 to 9999 at 100-nanosecond precision, while PostgreSQL's timestamps store values from 4713BC to 5874897AD with 1-microsecond precision.
public readonly struct NpgsqlDateTime : IEquatable<NpgsqlDateTime>, IComparable<NpgsqlDateTime>, IComparable, IComparer<NpgsqlDateTime>, IComparer
- Implements
- Inherited Members
Constructors
NpgsqlDateTime(NpgsqlDate)
public NpgsqlDateTime(NpgsqlDate date)
Parameters
date
NpgsqlDate
NpgsqlDateTime(NpgsqlDate, TimeSpan, DateTimeKind)
public NpgsqlDateTime(NpgsqlDate date, TimeSpan time, DateTimeKind kind = DateTimeKind.Unspecified)
Parameters
date
NpgsqlDatetime
TimeSpankind
DateTimeKind
NpgsqlDateTime(DateTime)
public NpgsqlDateTime(DateTime dateTime)
Parameters
dateTime
DateTime
NpgsqlDateTime(int, int, int, int, int, int, DateTimeKind)
public NpgsqlDateTime(int year, int month, int day, int hours, int minutes, int seconds, DateTimeKind kind = DateTimeKind.Unspecified)
Parameters
NpgsqlDateTime(int, int, int, int, int, int, int, DateTimeKind)
public NpgsqlDateTime(int year, int month, int day, int hours, int minutes, int seconds, int milliseconds, DateTimeKind kind = DateTimeKind.Unspecified)
Parameters
NpgsqlDateTime(long)
public NpgsqlDateTime(long ticks)
Parameters
ticks
long
NpgsqlDateTime(long, DateTimeKind)
public NpgsqlDateTime(long ticks, DateTimeKind kind)
Parameters
ticks
longkind
DateTimeKind
Fields
Epoch
public static readonly NpgsqlDateTime Epoch
Field Value
Era
public static readonly NpgsqlDateTime Era
Field Value
Infinity
public static readonly NpgsqlDateTime Infinity
Field Value
NegativeInfinity
public static readonly NpgsqlDateTime NegativeInfinity
Field Value
Properties
Date
public NpgsqlDate Date { get; }
Property Value
Day
public int Day { get; }
Property Value
DayOfWeek
public DayOfWeek DayOfWeek { get; }
Property Value
DayOfYear
public int DayOfYear { get; }
Property Value
Hour
public int Hour { get; }
Property Value
IsFinite
public bool IsFinite { get; }
Property Value
IsInfinity
public bool IsInfinity { get; }
Property Value
IsLeapYear
public bool IsLeapYear { get; }
Property Value
IsNegativeInfinity
public bool IsNegativeInfinity { get; }
Property Value
Kind
public DateTimeKind Kind { get; }
Property Value
Millisecond
public int Millisecond { get; }
Property Value
Minute
public int Minute { get; }
Property Value
Month
public int Month { get; }
Property Value
Now
public static NpgsqlDateTime Now { get; }
Property Value
Second
public int Second { get; }
Property Value
Ticks
public long Ticks { get; }
Property Value
Time
public TimeSpan Time { get; }
Property Value
Year
public int Year { get; }
Property Value
Methods
Add(NpgsqlTimeSpan)
Returns a new NpgsqlDateTime that adds the value of the specified TimeSpan to the value of this instance.
public NpgsqlDateTime Add(NpgsqlTimeSpan value)
Parameters
value
NpgsqlTimeSpanA positive or negative time interval.
Returns
- NpgsqlDateTime
An object whose value is the sum of the date and time represented by this instance and the time interval represented by value.
Add(TimeSpan)
Returns a new NpgsqlDateTime that adds the value of the specified NpgsqlTimeSpan to the value of this instance.
public NpgsqlDateTime Add(TimeSpan value)
Parameters
value
TimeSpanA positive or negative time interval.
Returns
- NpgsqlDateTime
An object whose value is the sum of the date and time represented by this instance and the time interval represented by value.
AddDays(double)
Returns a new NpgsqlDateTime that adds the specified number of days to the value of this instance.
public NpgsqlDateTime AddDays(double value)
Parameters
value
doubleA number of whole and fractional days. The value parameter can be negative or positive.
Returns
- NpgsqlDateTime
An object whose value is the sum of the date and time represented by this instance and the number of days represented by value.
AddHours(double)
Returns a new NpgsqlDateTime that adds the specified number of hours to the value of this instance.
public NpgsqlDateTime AddHours(double value)
Parameters
value
doubleA number of whole and fractional hours. The value parameter can be negative or positive.
Returns
- NpgsqlDateTime
An object whose value is the sum of the date and time represented by this instance and the number of hours represented by value.
AddMilliseconds(double)
Returns a new NpgsqlDateTime that adds the specified number of milliseconds to the value of this instance.
public NpgsqlDateTime AddMilliseconds(double value)
Parameters
value
doubleA number of whole and fractional milliseconds. The value parameter can be negative or positive. Note that this value is rounded to the nearest integer.
Returns
- NpgsqlDateTime
An object whose value is the sum of the date and time represented by this instance and the number of milliseconds represented by value.
AddMinutes(double)
Returns a new NpgsqlDateTime that adds the specified number of minutes to the value of this instance.
public NpgsqlDateTime AddMinutes(double value)
Parameters
value
doubleA number of whole and fractional minutes. The value parameter can be negative or positive.
Returns
- NpgsqlDateTime
An object whose value is the sum of the date and time represented by this instance and the number of minutes represented by value.
AddMonths(int)
Returns a new NpgsqlDateTime that adds the specified number of months to the value of this instance.
public NpgsqlDateTime AddMonths(int value)
Parameters
value
intA number of months. The months parameter can be negative or positive.
Returns
- NpgsqlDateTime
An object whose value is the sum of the date and time represented by this instance and months.
AddSeconds(double)
Returns a new NpgsqlDateTime that adds the specified number of minutes to the value of this instance.
public NpgsqlDateTime AddSeconds(double value)
Parameters
value
doubleA number of whole and fractional minutes. The value parameter can be negative or positive.
Returns
- NpgsqlDateTime
An object whose value is the sum of the date and time represented by this instance and the number of minutes represented by value.
AddTicks(long)
Returns a new NpgsqlDateTime that adds the specified number of ticks to the value of this instance.
public NpgsqlDateTime AddTicks(long value)
Parameters
value
longA number of 100-nanosecond ticks. The value parameter can be positive or negative.
Returns
- NpgsqlDateTime
An object whose value is the sum of the date and time represented by this instance and the time represented by value.
AddYears(int)
Returns a new NpgsqlDateTime that adds the specified number of years to the value of this instance.
public NpgsqlDateTime AddYears(int value)
Parameters
value
intA number of years. The value parameter can be negative or positive.
Returns
- NpgsqlDateTime
An object whose value is the sum of the date and time represented by this instance and the number of years represented by value.
Compare(NpgsqlDateTime, NpgsqlDateTime)
public int Compare(NpgsqlDateTime x, NpgsqlDateTime y)
Parameters
Returns
Compare(object, object)
public int Compare(object x, object y)
Parameters
Returns
CompareTo(NpgsqlDateTime)
public int CompareTo(NpgsqlDateTime other)
Parameters
other
NpgsqlDateTime
Returns
CompareTo(object)
public int CompareTo(object o)
Parameters
o
object
Returns
Equals(NpgsqlDateTime)
public bool Equals(NpgsqlDateTime other)
Parameters
other
NpgsqlDateTime
Returns
Equals(object)
public override bool Equals(object obj)
Parameters
obj
object
Returns
GetHashCode()
public override int GetHashCode()
Returns
Normalize()
public NpgsqlDateTime Normalize()
Returns
Parse(string)
public static NpgsqlDateTime Parse(string str)
Parameters
str
string
Returns
Subtract(NpgsqlDateTime)
public NpgsqlTimeSpan Subtract(NpgsqlDateTime timestamp)
Parameters
timestamp
NpgsqlDateTime
Returns
Subtract(NpgsqlTimeSpan)
public NpgsqlDateTime Subtract(NpgsqlTimeSpan interval)
Parameters
interval
NpgsqlTimeSpan
Returns
ToDateTime()
Cast of an NpgsqlDateTime to a DateTime.
public DateTime ToDateTime()
Returns
ToLocalTime()
Converts the value of the current NpgsqlDateTime object to local time.
public NpgsqlDateTime ToLocalTime()
Returns
Remarks
See the MSDN documentation for DateTime.ToLocalTime(). Note: this method only takes into account the time zone's base offset, and does not respect daylight savings. See https://github.com/npgsql/npgsql/pull/684 for more details.
ToNpgsqlDateTime(DateTime)
public static NpgsqlDateTime ToNpgsqlDateTime(DateTime dateTime)
Parameters
dateTime
DateTime
Returns
ToString()
public override string ToString()
Returns
ToUniversalTime()
Converts the value of the current NpgsqlDateTime object to Coordinated Universal Time (UTC).
public NpgsqlDateTime ToUniversalTime()
Returns
Remarks
See the MSDN documentation for DateTime.ToUniversalTime(). Note: this method only takes into account the time zone's base offset, and does not respect daylight savings. See https://github.com/npgsql/npgsql/pull/684 for more details.
Operators
operator +(NpgsqlDateTime, NpgsqlTimeSpan)
public static NpgsqlDateTime operator +(NpgsqlDateTime timestamp, NpgsqlTimeSpan interval)
Parameters
timestamp
NpgsqlDateTimeinterval
NpgsqlTimeSpan
Returns
operator +(NpgsqlTimeSpan, NpgsqlDateTime)
public static NpgsqlDateTime operator +(NpgsqlTimeSpan interval, NpgsqlDateTime timestamp)
Parameters
interval
NpgsqlTimeSpantimestamp
NpgsqlDateTime
Returns
operator ==(NpgsqlDateTime, NpgsqlDateTime)
public static bool operator ==(NpgsqlDateTime x, NpgsqlDateTime y)
Parameters
Returns
explicit operator DateTime(NpgsqlDateTime)
Explicit cast of an NpgsqlDateTime to a DateTime.
public static explicit operator DateTime(NpgsqlDateTime npgsqlDateTime)
Parameters
npgsqlDateTime
NpgsqlDateTimeAn NpgsqlDateTime.
Returns
operator >(NpgsqlDateTime, NpgsqlDateTime)
public static bool operator >(NpgsqlDateTime x, NpgsqlDateTime y)
Parameters
Returns
operator >=(NpgsqlDateTime, NpgsqlDateTime)
public static bool operator >=(NpgsqlDateTime x, NpgsqlDateTime y)
Parameters
Returns
implicit operator NpgsqlDateTime(DateTime)
Implicit cast of a DateTime to an NpgsqlDateTime
public static implicit operator NpgsqlDateTime(DateTime dateTime)
Parameters
Returns
- NpgsqlDateTime
An equivalent NpgsqlDateTime.
operator !=(NpgsqlDateTime, NpgsqlDateTime)
public static bool operator !=(NpgsqlDateTime x, NpgsqlDateTime y)
Parameters
Returns
operator <(NpgsqlDateTime, NpgsqlDateTime)
public static bool operator <(NpgsqlDateTime x, NpgsqlDateTime y)
Parameters
Returns
operator <=(NpgsqlDateTime, NpgsqlDateTime)
public static bool operator <=(NpgsqlDateTime x, NpgsqlDateTime y)
Parameters
Returns
operator -(NpgsqlDateTime, NpgsqlDateTime)
public static NpgsqlTimeSpan operator -(NpgsqlDateTime x, NpgsqlDateTime y)
Parameters
Returns
operator -(NpgsqlDateTime, NpgsqlTimeSpan)
public static NpgsqlDateTime operator -(NpgsqlDateTime timestamp, NpgsqlTimeSpan interval)
Parameters
timestamp
NpgsqlDateTimeinterval
NpgsqlTimeSpan