Table of Contents

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 NpgsqlDate
time TimeSpan
kind 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

year int
month int
day int
hours int
minutes int
seconds int
kind DateTimeKind

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

year int
month int
day int
hours int
minutes int
seconds int
milliseconds int
kind DateTimeKind

NpgsqlDateTime(long)

public NpgsqlDateTime(long ticks)

Parameters

ticks long

NpgsqlDateTime(long, DateTimeKind)

public NpgsqlDateTime(long ticks, DateTimeKind kind)

Parameters

ticks long
kind DateTimeKind

Fields

Epoch

public static readonly NpgsqlDateTime Epoch

Field Value

NpgsqlDateTime

Era

public static readonly NpgsqlDateTime Era

Field Value

NpgsqlDateTime

Infinity

public static readonly NpgsqlDateTime Infinity

Field Value

NpgsqlDateTime

NegativeInfinity

public static readonly NpgsqlDateTime NegativeInfinity

Field Value

NpgsqlDateTime

Properties

Date

public NpgsqlDate Date { get; }

Property Value

NpgsqlDate

Day

public int Day { get; }

Property Value

int

DayOfWeek

public DayOfWeek DayOfWeek { get; }

Property Value

DayOfWeek

DayOfYear

public int DayOfYear { get; }

Property Value

int

Hour

public int Hour { get; }

Property Value

int

IsFinite

public bool IsFinite { get; }

Property Value

bool

IsInfinity

public bool IsInfinity { get; }

Property Value

bool

IsLeapYear

public bool IsLeapYear { get; }

Property Value

bool

IsNegativeInfinity

public bool IsNegativeInfinity { get; }

Property Value

bool

Kind

public DateTimeKind Kind { get; }

Property Value

DateTimeKind

Millisecond

public int Millisecond { get; }

Property Value

int

Minute

public int Minute { get; }

Property Value

int

Month

public int Month { get; }

Property Value

int

Now

public static NpgsqlDateTime Now { get; }

Property Value

NpgsqlDateTime

Second

public int Second { get; }

Property Value

int

Ticks

public long Ticks { get; }

Property Value

long

Time

public TimeSpan Time { get; }

Property Value

TimeSpan

Year

public int Year { get; }

Property Value

int

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 NpgsqlTimeSpan

A 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 TimeSpan

A 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 double

A 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 double

A 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 double

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

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 double

A 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 int

A 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 double

A 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 long

A 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 int

A 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

x NpgsqlDateTime
y NpgsqlDateTime

Returns

int

Compare(object, object)

public int Compare(object x, object y)

Parameters

x object
y object

Returns

int

CompareTo(NpgsqlDateTime)

public int CompareTo(NpgsqlDateTime other)

Parameters

other NpgsqlDateTime

Returns

int

CompareTo(object)

public int CompareTo(object o)

Parameters

o object

Returns

int

Equals(NpgsqlDateTime)

public bool Equals(NpgsqlDateTime other)

Parameters

other NpgsqlDateTime

Returns

bool

Equals(object)

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

Normalize()

public NpgsqlDateTime Normalize()

Returns

NpgsqlDateTime

Parse(string)

public static NpgsqlDateTime Parse(string str)

Parameters

str string

Returns

NpgsqlDateTime

Subtract(NpgsqlDateTime)

public NpgsqlTimeSpan Subtract(NpgsqlDateTime timestamp)

Parameters

timestamp NpgsqlDateTime

Returns

NpgsqlTimeSpan

Subtract(NpgsqlTimeSpan)

public NpgsqlDateTime Subtract(NpgsqlTimeSpan interval)

Parameters

interval NpgsqlTimeSpan

Returns

NpgsqlDateTime

ToDateTime()

Cast of an NpgsqlDateTime to a DateTime.

public DateTime ToDateTime()

Returns

DateTime

An equivalent DateTime.

ToLocalTime()

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

public NpgsqlDateTime ToLocalTime()

Returns

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)

public static NpgsqlDateTime ToNpgsqlDateTime(DateTime dateTime)

Parameters

dateTime DateTime

Returns

NpgsqlDateTime

ToString()

public override string ToString()

Returns

string

ToUniversalTime()

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

public NpgsqlDateTime ToUniversalTime()

Returns

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

operator +(NpgsqlDateTime, NpgsqlTimeSpan)

public static NpgsqlDateTime operator +(NpgsqlDateTime timestamp, NpgsqlTimeSpan interval)

Parameters

timestamp NpgsqlDateTime
interval NpgsqlTimeSpan

Returns

NpgsqlDateTime

operator +(NpgsqlTimeSpan, NpgsqlDateTime)

public static NpgsqlDateTime operator +(NpgsqlTimeSpan interval, NpgsqlDateTime timestamp)

Parameters

interval NpgsqlTimeSpan
timestamp NpgsqlDateTime

Returns

NpgsqlDateTime

operator ==(NpgsqlDateTime, NpgsqlDateTime)

public static bool operator ==(NpgsqlDateTime x, NpgsqlDateTime y)

Parameters

x NpgsqlDateTime
y NpgsqlDateTime

Returns

bool

explicit operator DateTime(NpgsqlDateTime)

Explicit cast of an NpgsqlDateTime to a DateTime.

public static explicit operator DateTime(NpgsqlDateTime npgsqlDateTime)

Parameters

npgsqlDateTime NpgsqlDateTime

An NpgsqlDateTime.

Returns

DateTime

An equivalent DateTime.

operator >(NpgsqlDateTime, NpgsqlDateTime)

public static bool operator >(NpgsqlDateTime x, NpgsqlDateTime y)

Parameters

x NpgsqlDateTime
y NpgsqlDateTime

Returns

bool

operator >=(NpgsqlDateTime, NpgsqlDateTime)

public static bool operator >=(NpgsqlDateTime x, NpgsqlDateTime y)

Parameters

x NpgsqlDateTime
y NpgsqlDateTime

Returns

bool

implicit operator NpgsqlDateTime(DateTime)

Implicit cast of a DateTime to an NpgsqlDateTime

public static implicit operator NpgsqlDateTime(DateTime dateTime)

Parameters

dateTime DateTime

A DateTime

Returns

NpgsqlDateTime

An equivalent NpgsqlDateTime.

operator !=(NpgsqlDateTime, NpgsqlDateTime)

public static bool operator !=(NpgsqlDateTime x, NpgsqlDateTime y)

Parameters

x NpgsqlDateTime
y NpgsqlDateTime

Returns

bool

operator <(NpgsqlDateTime, NpgsqlDateTime)

public static bool operator <(NpgsqlDateTime x, NpgsqlDateTime y)

Parameters

x NpgsqlDateTime
y NpgsqlDateTime

Returns

bool

operator <=(NpgsqlDateTime, NpgsqlDateTime)

public static bool operator <=(NpgsqlDateTime x, NpgsqlDateTime y)

Parameters

x NpgsqlDateTime
y NpgsqlDateTime

Returns

bool

operator -(NpgsqlDateTime, NpgsqlDateTime)

public static NpgsqlTimeSpan operator -(NpgsqlDateTime x, NpgsqlDateTime y)

Parameters

x NpgsqlDateTime
y NpgsqlDateTime

Returns

NpgsqlTimeSpan

operator -(NpgsqlDateTime, NpgsqlTimeSpan)

public static NpgsqlDateTime operator -(NpgsqlDateTime timestamp, NpgsqlTimeSpan interval)

Parameters

timestamp NpgsqlDateTime
interval NpgsqlTimeSpan

Returns

NpgsqlDateTime