Search Results for

    Show / Hide Table of Contents

    Struct NpgsqlDateTime

    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.

    Implements
    IEquatable<NpgsqlDateTime>
    IComparable<NpgsqlDateTime>
    IComparable
    IComparer<NpgsqlDateTime>
    IComparer
    Inherited Members
    Object.Equals(Object, Object)
    Object.GetType()
    Object.ReferenceEquals(Object, Object)
    Namespace: NpgsqlTypes
    Assembly: Npgsql.dll
    Syntax
    [Obsolete("For values outside the range of DateTime, consider using NodaTime (range -9998 to 9999), or read the value as a 'long'. See https://www.npgsql.org/doc/types/datetime.html for more information.")]
    [Serializable]
    public readonly struct NpgsqlDateTime : IEquatable<NpgsqlDateTime>, IComparable<NpgsqlDateTime>, IComparable, IComparer<NpgsqlDateTime>, IComparer

    Constructors

    NpgsqlDateTime(NpgsqlDate)

    Declaration
    public NpgsqlDateTime(NpgsqlDate date)
    Parameters
    Type Name Description
    NpgsqlDate date

    NpgsqlDateTime(NpgsqlDate, TimeSpan, DateTimeKind)

    Declaration
    public NpgsqlDateTime(NpgsqlDate date, TimeSpan time, DateTimeKind kind = DateTimeKind.Unspecified)
    Parameters
    Type Name Description
    NpgsqlDate date
    TimeSpan time
    DateTimeKind kind

    NpgsqlDateTime(DateTime)

    Declaration
    public NpgsqlDateTime(DateTime dateTime)
    Parameters
    Type Name Description
    DateTime dateTime

    NpgsqlDateTime(Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind)

    Declaration
    public NpgsqlDateTime(int year, int month, int day, int hours, int minutes, int seconds, DateTimeKind kind = DateTimeKind.Unspecified)
    Parameters
    Type Name Description
    Int32 year
    Int32 month
    Int32 day
    Int32 hours
    Int32 minutes
    Int32 seconds
    DateTimeKind kind

    NpgsqlDateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind)

    Declaration
    public NpgsqlDateTime(int year, int month, int day, int hours, int minutes, int seconds, int milliseconds, DateTimeKind kind = DateTimeKind.Unspecified)
    Parameters
    Type Name Description
    Int32 year
    Int32 month
    Int32 day
    Int32 hours
    Int32 minutes
    Int32 seconds
    Int32 milliseconds
    DateTimeKind kind

    NpgsqlDateTime(Int64)

    Declaration
    public NpgsqlDateTime(long ticks)
    Parameters
    Type Name Description
    Int64 ticks

    NpgsqlDateTime(Int64, DateTimeKind)

    Declaration
    public NpgsqlDateTime(long ticks, DateTimeKind kind)
    Parameters
    Type Name Description
    Int64 ticks
    DateTimeKind kind

    Fields

    Epoch

    Declaration
    public static readonly NpgsqlDateTime Epoch
    Field Value
    Type Description
    NpgsqlDateTime

    Era

    Declaration
    public static readonly NpgsqlDateTime Era
    Field Value
    Type Description
    NpgsqlDateTime

    Infinity

    Declaration
    public static readonly NpgsqlDateTime Infinity
    Field Value
    Type Description
    NpgsqlDateTime

    NegativeInfinity

    Declaration
    public static readonly NpgsqlDateTime NegativeInfinity
    Field Value
    Type Description
    NpgsqlDateTime

    Properties

    Date

    Declaration
    public readonly NpgsqlDate Date { get; }
    Property Value
    Type Description
    NpgsqlDate

    Day

    Declaration
    public readonly int Day { get; }
    Property Value
    Type Description
    Int32

    DayOfWeek

    Declaration
    public readonly DayOfWeek DayOfWeek { get; }
    Property Value
    Type Description
    DayOfWeek

    DayOfYear

    Declaration
    public readonly int DayOfYear { get; }
    Property Value
    Type Description
    Int32

    Hour

    Declaration
    public readonly int Hour { get; }
    Property Value
    Type Description
    Int32

    IsFinite

    Declaration
    public readonly bool IsFinite { get; }
    Property Value
    Type Description
    Boolean

    IsInfinity

    Declaration
    public readonly bool IsInfinity { get; }
    Property Value
    Type Description
    Boolean

    IsLeapYear

    Declaration
    public readonly bool IsLeapYear { get; }
    Property Value
    Type Description
    Boolean

    IsNegativeInfinity

    Declaration
    public readonly bool IsNegativeInfinity { get; }
    Property Value
    Type Description
    Boolean

    Kind

    Declaration
    public readonly DateTimeKind Kind { get; }
    Property Value
    Type Description
    DateTimeKind

    Millisecond

    Declaration
    public readonly int Millisecond { get; }
    Property Value
    Type Description
    Int32

    Minute

    Declaration
    public readonly int Minute { get; }
    Property Value
    Type Description
    Int32

    Month

    Declaration
    public readonly int Month { get; }
    Property Value
    Type Description
    Int32

    Now

    Declaration
    public static readonly NpgsqlDateTime Now { get; }
    Property Value
    Type Description
    NpgsqlDateTime

    Second

    Declaration
    public readonly int Second { get; }
    Property Value
    Type Description
    Int32

    Ticks

    Declaration
    public readonly long Ticks { get; }
    Property Value
    Type Description
    Int64

    Time

    Declaration
    public readonly TimeSpan Time { get; }
    Property Value
    Type Description
    TimeSpan

    Year

    Declaration
    public readonly int Year { get; }
    Property Value
    Type Description
    Int32

    Methods

    Add(in NpgsqlTimeSpan)

    Returns a new NpgsqlDateTime that adds the value of the specified NpgsqlTimeSpan to the value of this instance.

    Declaration
    public readonly NpgsqlDateTime Add(in NpgsqlTimeSpan value)
    Parameters
    Type Name Description
    NpgsqlTimeSpan value

    An NpgsqlTimeSpan interval.

    Returns
    Type Description
    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 TimeSpan to the value of this instance.

    Declaration
    public readonly NpgsqlDateTime Add(TimeSpan value)
    Parameters
    Type Name Description
    TimeSpan value

    A positive or negative time interval.

    Returns
    Type Description
    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.

    Declaration
    public readonly NpgsqlDateTime AddDays(double value)
    Parameters
    Type Name Description
    Double value

    A number of whole and fractional days. The value parameter can be negative or positive.

    Returns
    Type Description
    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.

    Declaration
    public readonly NpgsqlDateTime AddHours(double value)
    Parameters
    Type Name Description
    Double value

    A number of whole and fractional hours. The value parameter can be negative or positive.

    Returns
    Type Description
    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.

    Declaration
    public readonly NpgsqlDateTime AddMilliseconds(double value)
    Parameters
    Type Name Description
    Double value

    A 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
    Type Description
    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.

    Declaration
    public readonly NpgsqlDateTime AddMinutes(double value)
    Parameters
    Type Name Description
    Double value

    A number of whole and fractional minutes. The value parameter can be negative or positive.

    Returns
    Type Description
    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(Int32)

    Returns a new NpgsqlDateTime that adds the specified number of months to the value of this instance.

    Declaration
    public readonly NpgsqlDateTime AddMonths(int value)
    Parameters
    Type Name Description
    Int32 value

    A number of months. The months parameter can be negative or positive.

    Returns
    Type Description
    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.

    Declaration
    public readonly NpgsqlDateTime AddSeconds(double value)
    Parameters
    Type Name Description
    Double value

    A number of whole and fractional minutes. The value parameter can be negative or positive.

    Returns
    Type Description
    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(Int64)

    Returns a new NpgsqlDateTime that adds the specified number of ticks to the value of this instance.

    Declaration
    public readonly NpgsqlDateTime AddTicks(long value)
    Parameters
    Type Name Description
    Int64 value

    A number of 100-nanosecond ticks. The value parameter can be positive or negative.

    Returns
    Type Description
    NpgsqlDateTime

    An object whose value is the sum of the date and time represented by this instance and the time represented by value.

    AddYears(Int32)

    Returns a new NpgsqlDateTime that adds the specified number of years to the value of this instance.

    Declaration
    public readonly NpgsqlDateTime AddYears(int value)
    Parameters
    Type Name Description
    Int32 value

    A number of years. The value parameter can be negative or positive.

    Returns
    Type Description
    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)

    Declaration
    public readonly int Compare(NpgsqlDateTime x, NpgsqlDateTime y)
    Parameters
    Type Name Description
    NpgsqlDateTime x
    NpgsqlDateTime y
    Returns
    Type Description
    Int32

    Compare(Object, Object)

    Declaration
    public readonly int Compare(object x, object y)
    Parameters
    Type Name Description
    Object x
    Object y
    Returns
    Type Description
    Int32

    CompareTo(NpgsqlDateTime)

    Declaration
    public readonly int CompareTo(NpgsqlDateTime other)
    Parameters
    Type Name Description
    NpgsqlDateTime other
    Returns
    Type Description
    Int32

    CompareTo(Object)

    Declaration
    public readonly int CompareTo(object o)
    Parameters
    Type Name Description
    Object o
    Returns
    Type Description
    Int32

    Equals(NpgsqlDateTime)

    Declaration
    public readonly bool Equals(NpgsqlDateTime other)
    Parameters
    Type Name Description
    NpgsqlDateTime other
    Returns
    Type Description
    Boolean

    Equals(Object)

    Declaration
    public override readonly bool Equals(object obj)
    Parameters
    Type Name Description
    Object obj
    Returns
    Type Description
    Boolean
    Overrides
    ValueType.Equals(Object)

    GetHashCode()

    Declaration
    public override readonly int GetHashCode()
    Returns
    Type Description
    Int32
    Overrides
    ValueType.GetHashCode()

    Normalize()

    Declaration
    public readonly NpgsqlDateTime Normalize()
    Returns
    Type Description
    NpgsqlDateTime

    Parse(String)

    Declaration
    public static NpgsqlDateTime Parse(string str)
    Parameters
    Type Name Description
    String str
    Returns
    Type Description
    NpgsqlDateTime

    Subtract(NpgsqlDateTime)

    Declaration
    public readonly NpgsqlTimeSpan Subtract(NpgsqlDateTime timestamp)
    Parameters
    Type Name Description
    NpgsqlDateTime timestamp
    Returns
    Type Description
    NpgsqlTimeSpan

    Subtract(in NpgsqlTimeSpan)

    Declaration
    public readonly NpgsqlDateTime Subtract(in NpgsqlTimeSpan interval)
    Parameters
    Type Name Description
    NpgsqlTimeSpan interval
    Returns
    Type Description
    NpgsqlDateTime

    ToDateTime()

    Cast of an NpgsqlDateTime to a DateTime.

    Declaration
    public readonly DateTime ToDateTime()
    Returns
    Type Description
    DateTime

    An equivalent DateTime.

    ToLocalTime()

    Converts the value of the current NpgsqlDateTime object to local time.

    Declaration
    public readonly NpgsqlDateTime ToLocalTime()
    Returns
    Type Description
    NpgsqlDateTime
    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)

    Declaration
    public static NpgsqlDateTime ToNpgsqlDateTime(DateTime dateTime)
    Parameters
    Type Name Description
    DateTime dateTime
    Returns
    Type Description
    NpgsqlDateTime

    ToString()

    Declaration
    public override readonly string ToString()
    Returns
    Type Description
    String
    Overrides
    ValueType.ToString()

    ToUniversalTime()

    Converts the value of the current NpgsqlDateTime object to Coordinated Universal Time (UTC).

    Declaration
    public readonly NpgsqlDateTime ToUniversalTime()
    Returns
    Type Description
    NpgsqlDateTime
    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

    Addition(NpgsqlDateTime, NpgsqlTimeSpan)

    Declaration
    public static NpgsqlDateTime operator +(NpgsqlDateTime timestamp, NpgsqlTimeSpan interval)
    Parameters
    Type Name Description
    NpgsqlDateTime timestamp
    NpgsqlTimeSpan interval
    Returns
    Type Description
    NpgsqlDateTime

    Addition(NpgsqlTimeSpan, NpgsqlDateTime)

    Declaration
    public static NpgsqlDateTime operator +(NpgsqlTimeSpan interval, NpgsqlDateTime timestamp)
    Parameters
    Type Name Description
    NpgsqlTimeSpan interval
    NpgsqlDateTime timestamp
    Returns
    Type Description
    NpgsqlDateTime

    Equality(NpgsqlDateTime, NpgsqlDateTime)

    Declaration
    public static bool operator ==(NpgsqlDateTime x, NpgsqlDateTime y)
    Parameters
    Type Name Description
    NpgsqlDateTime x
    NpgsqlDateTime y
    Returns
    Type Description
    Boolean

    Explicit(NpgsqlDateTime to DateTime)

    Explicit cast of an NpgsqlDateTime to a DateTime.

    Declaration
    public static explicit operator DateTime(NpgsqlDateTime npgsqlDateTime)
    Parameters
    Type Name Description
    NpgsqlDateTime npgsqlDateTime

    An NpgsqlDateTime.

    Returns
    Type Description
    DateTime

    An equivalent DateTime.

    GreaterThan(NpgsqlDateTime, NpgsqlDateTime)

    Declaration
    public static bool operator>(NpgsqlDateTime x, NpgsqlDateTime y)
    Parameters
    Type Name Description
    NpgsqlDateTime x
    NpgsqlDateTime y
    Returns
    Type Description
    Boolean

    GreaterThanOrEqual(NpgsqlDateTime, NpgsqlDateTime)

    Declaration
    public static bool operator >=(NpgsqlDateTime x, NpgsqlDateTime y)
    Parameters
    Type Name Description
    NpgsqlDateTime x
    NpgsqlDateTime y
    Returns
    Type Description
    Boolean

    Implicit(DateTime to NpgsqlDateTime)

    Implicit cast of a DateTime to an NpgsqlDateTime

    Declaration
    public static implicit operator NpgsqlDateTime(DateTime dateTime)
    Parameters
    Type Name Description
    DateTime dateTime

    A DateTime

    Returns
    Type Description
    NpgsqlDateTime

    An equivalent NpgsqlDateTime.

    Inequality(NpgsqlDateTime, NpgsqlDateTime)

    Declaration
    public static bool operator !=(NpgsqlDateTime x, NpgsqlDateTime y)
    Parameters
    Type Name Description
    NpgsqlDateTime x
    NpgsqlDateTime y
    Returns
    Type Description
    Boolean

    LessThan(NpgsqlDateTime, NpgsqlDateTime)

    Declaration
    public static bool operator <(NpgsqlDateTime x, NpgsqlDateTime y)
    Parameters
    Type Name Description
    NpgsqlDateTime x
    NpgsqlDateTime y
    Returns
    Type Description
    Boolean

    LessThanOrEqual(NpgsqlDateTime, NpgsqlDateTime)

    Declaration
    public static bool operator <=(NpgsqlDateTime x, NpgsqlDateTime y)
    Parameters
    Type Name Description
    NpgsqlDateTime x
    NpgsqlDateTime y
    Returns
    Type Description
    Boolean

    Subtraction(NpgsqlDateTime, NpgsqlDateTime)

    Declaration
    public static NpgsqlTimeSpan operator -(NpgsqlDateTime x, NpgsqlDateTime y)
    Parameters
    Type Name Description
    NpgsqlDateTime x
    NpgsqlDateTime y
    Returns
    Type Description
    NpgsqlTimeSpan

    Subtraction(NpgsqlDateTime, NpgsqlTimeSpan)

    Declaration
    public static NpgsqlDateTime operator -(NpgsqlDateTime timestamp, NpgsqlTimeSpan interval)
    Parameters
    Type Name Description
    NpgsqlDateTime timestamp
    NpgsqlTimeSpan interval
    Returns
    Type Description
    NpgsqlDateTime

    Implements

    System.IEquatable<T>
    System.IComparable<T>
    System.IComparable
    System.Collections.Generic.IComparer<T>
    System.Collections.IComparer
    In This Article
    Back to top © Copyright 2022 The Npgsql Development Team