Skip Headers

Oracle® Data Provider for .NET Developer's Guide
Release 9.2.0.4

Part Number B10961-01
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to beginning of chapter Go to next page

Oracle.DataAccess.Types Namespace (ODP.NET Types), 3 of 19


OracleDate Structure

The OracleDate structure represents the Oracle DATE datatype to be stored in or retrieved from a database. Each OracleDate stores the following information: year, month, day, hour, minute, and second.

Class Inheritance

Object

  ValueType

    OracleDate

Declaration
// C#
public struct OracleDate : IComparable
Thread Safety

All public static methods are thread-safe, although instance methods do not guarantee thread safety.

Remarks
Example
// C#
// Compute the number of days between minimum values of
// the OracleDate and DateTime structures
OracleDate od1 = new OracleDate(DateTime.MinValue);
OracleDate od2 = OracleDate.MinValue;

// Set the nls_date_format for the ToString()
OracleGlobalization og = OracleGlobalization.GetClientInfo();
og.DateFormat = "DD-MON-YYYY BC";
OracleGlobalization.SetThreadInfo(og);

Console.WriteLine("DateTime.MinValue   = " + od1.ToString());
Console.WriteLine("OracleDate.MinValue = " + od2.ToString());

// Compare the two values
int result = od1.CompareTo(od2);

// Output the difference in number of days (as a positive value)
if (result == 0)
  Console.WriteLine("DateTime and OracleDate Minimum values"+
    " are equal.");
else if (result < 0)
  Console.WriteLine("DateTime Minimum value is before OracleDate" +
    " Minumum value by " + od2.GetDaysBetween(od1) + " days.");
else if (result > 0)
  Console.WriteLine("OracleDate Minimum value is before DateTime" +
    " Minumum value by " + od1.GetDaysBetween(od2) + " days.");

Requirements

Namespace: Oracle.DataAccess.Types

Assembly: Oracle.DataAccess.dll

See Also:

OracleDate Members

OracleDate members are listed in the following tables:

OracleDate Constructors

OracleDate constructors are listed in Table 5-14

Table 5-14 OracleDate Constructors
Constructor Description

OracleDate Constructors

Instantiates a new instance of OracleDate structure (Overloaded)

OracleDate Static Fields

The OracleDate static fields are listed in Table 5-15.

Table 5-15 OracleDate Static Fields  
Field Description

MaxValue

Represents the maximum valid date for an OracleDate structure, which is December 31, 9999 23:59:59

MinValue

Represents the minimum valid date for an OracleDate structure, which is January 1, -4712 0:0:0

Null

Represents a null value that can be assigned to the value of an OracleDate structure instance

OracleDate Static Methods

The OracleDate static methods are listed in Table 5-16.

Table 5-16 OracleDate Static Methods  
Methods Description

Equals

Determines if two OracleDate values are equal (Overloaded)

GreaterThan

Determines if the first of two OracleDate values is greater than the second

GreaterThanOrEqual

Determines if the first of two OracleDate values is greater than or equal to the second

LessThan

Determines if the first of two OracleDate values is less than the second

LessThanOrEqual

Determines if the first of two OracleDate values is less than or equal to the second

NotEquals

Determines if two OracleDate values are not equal

GetSysDate

Returns an OracleDate structure that represents the current date and time

Parse

Returns an OracleDate structure and sets its value using a string

OracleDate Static Operators

The OracleDate static operators are listed in Table 5-17.

Table 5-17 OracleDate Static Operators  
Operator Description

operator ==

Determines if two OracleDate values are the same

operator >

Determines if the first of two OracleDate values is greater than the second

operator >=

Determines if the first of two OracleDate values is greater than or equal to the second

operator !=

Determines if the two OracleDate values are not equal

operator <

Determines if the first of two OracleDate values is less than the second

operator <=

Determines if the first of two OracleDate values is less than or equal to the second

OracleDate Static Type Conversions

The OracleDate static type conversions are listed in Table 5-18.

Table 5-18 OracleDate Static Type Conversions  
Operator Description

explicit operator DateTime

Converts a structure to a DateTime structure

explicit operator OracleDate

Converts a structure to an OracleDate structure (Overloaded)

OracleDate Properties

The OracleDate properties are listed in Table 5-19.

Table 5-19 OracleDate Properties  
Properties Description

BinData

Gets an array of bytes that represents an Oracle DATE in Oracle internal format

Day

Gets the day component of an OracleDate method

IsNull

Indicates whether the current instance has a null value

Hour

Gets the hour component of an OracleDate

Minute

Gets the minute component of an OracleDate

Month

Gets the month component of an OracleDate

Second

Gets the second component of an OracleDate

Value

Gets the date and time that is stored in the OracleDate structure

Year

Gets the year component of an OracleDate

OracleDate Methods

The OracleDate methods are listed in Table 5-20.

Table 5-20 OracleDate Methods  
Methods Description

CompareTo

Compares the current OracleDate instance to an object, and returns an integer that represents their relative values

Equals

Determines whether an object has the same date and time as the current OracleDate instance (Overloaded)

GetHashCode

Returns a hash code for the OracleDate instance

GetDaysBetween

Calculates the number of days between the current OracleDate instance and an OracleDate structure

GetType

Inherited from Object

ToOracleTimeStamp

Converts the current OracleDate structure to an OracleTimeStamp structure

ToString

Converts the current OracleDate structure to a string

See Also:

OracleDate Constructors

The OracleDate constructors instantiates a new instance of the OracleDate structure.

Overload List:

OracleDate(DateTime)

This constructor creates a new instance of the OracleDate structure and sets its value for date and time using the supplied DateTime value.

Declaration
// C#
public OracleDate (DateTime dt);
Parameters
Remarks

The OracleDate structure only supports up to a second precision. The time value in the provided DateTime structure that has a precision smaller than second is ignored.

See Also:

OracleDate(string)

This constructor creates a new instance of the OracleDate structure and sets its value using the supplied string.

Declaration
// C#
public OracleDate (string dateStr);
Parameters
Exceptions

ArgumentException - The dateStr is an invalid string representation of an Oracle DATE or the dateStr is not in the date format specified by the thread's OracleGlobalization.DateFormat property, which represents Oracle's NLS_DATE_FORMAT parameter.

ArgumentNullException - The dateStr is null.

Remarks

The names and abbreviations used for months and days are in the language specified by the DateLanguage and Calendar properties of the thread's OracleGlobalization object. If any of the thread's globalization properties are set to null or an empty string, the client computer's settings are used.

Example
// C#
// Set the nls_date_format for the Parse() method
OracleGlobalization og = OracleGlobalization.GetClientInfo();
og.DateFormat = "YYYY-MON-DD";
OracleGlobalization.SetThreadInfo(og);

// construct OracleDate from a string using the DateFormat specified.
OracleDate od = new OracleDate("1999-NOV-11");

// Set the nls_date_format for the OracleDate(string) constructor
og.DateFormat = "DD-MON-YYYY";
OracleGlobalization.SetThreadInfo(og);

Console.WriteLine(od.ToString()); // Prints 11-NOV-1999


See Also:

OracleDate(int, int, int)

This constructor creates a new instance of the OracleDate structure and set its value for date using the supplied year, month, and day.

Declaration
// C#
public OracleDate (int year, int month, int day);
Parameters
Exceptions

ArgumentOutOfRangeException - The argument value for one or more of the parameters is out of the specified range.

ArgumentException - The argument values of the parameters cannot be used to construct a valid OracleDate (that is, the day is out of range for the month).

See Also:

OracleDate(int, int, int, int, int, int)

This constructor creates a new instance of the OracleDate structure and set its value for time using the supplied year, month, day, hour, minute, and second.

Declaration
// C#
public OracleDate (int year, int month, int day, int hour, int minute, int 
second);
Parameters
Exceptions

ArgumentOutOfRangeException - The argument value for one or more of the parameters is out of the specified range.

ArgumentException - The argument values of the parameters cannot be used to construct a valid OracleDate (that is, the day is out of range for the month).

See Also:

OracleDate(byte [ ])

This constructor creates a new instance of the OracleDate structure and sets its value to the provided byte array, which is in the internal Oracle DATE format.

Declaration
// C#
public OracleDate(byte [] bytes);
Parameters
Exceptions

ArgumentException - bytes is null or bytes is not in internal Oracle DATE format or bytes is not a valid Oracle DATE.

See Also:

OracleDate Static Fields

The OracleDate static fields are listed in Table 5-21.

Table 5-21 OracleDate Static Fields  
Field Description

MaxValue

Represents the maximum valid date for an OracleDate structure, which is December 31, 9999 23:59:59

MinValue

Represents the minimum valid date for an OracleDate structure, which is January 1, -4712 0:0:0

Null

Represents a null value that can be assigned to the value of an OracleDate structure instance

See Also:

MaxValue

This static field represents the maximum valid date for an OracleDate structure, which is December 31, 9999 23:59:59.

Declaration
// C#
public static readonly OracleDate MaxValue;

See Also:

MinValue

This static field represents the minimum valid date for an OracleDate structure, which is January 1, -4712.

Declaration
// C#
public static readonly OracleDate MinValue;

See Also:

Null

This static field represents a null value that can be assigned to the value of an OracleDate instance.

Declaration
// C#
public static readonly OracleDate Null;

See Also:

OracleDate Static Methods

The OracleDate static methods are listed in Table 5-22.

Table 5-22 OracleDate Static Methods  
Methods Description

Equals

Determines if two OracleDate values are equal (Overloaded)

GreaterThan

Determines if the first of two OracleDate values is greater than the second

GreaterThanOrEqual

Determines if the first of two OracleDate values is greater than or equal to the second

LessThan

Determines if the first of two OracleDate values is less than the second

LessThanOrEqual

Determines if the first of two OracleDate values is less than or equal to the second

NotEquals

Determines if two OracleDate values are not equal

GetSysDate

Returns an OracleDate structure that represents the current date and time

Parse

Returns an OracleDate structure and sets its value using a string

See Also:

Equals

Overloads Object

This method determines if two OracleDate values are equal.

Declaration
// C#
public static bool Equals(OracleDate value1, OracleDate value2);
Parameters
Return Value

Returns true if two OracleDate values are equal; otherwise, returns false.

Remarks

The following rules apply to the behavior of this method.

GreaterThan

This method determines if the first of two OracleDate values is greater than the second.

Declaration
// C#
public static bool GreaterThan(OracleDate value1, OracleDate value2);
Parameters
Return Value

Returns true if the first of two OracleDate values is greater than the second; otherwise, returns false.

Remarks

The following rules apply to the behavior of this method.

GreaterThanOrEqual

This method determines if the first of two OracleDate values is greater than or equal to the second.

Declaration
// C#
public static bool GreaterThanOrEqual(OracleDate value1, OracleDate value2);
Parameters
Return Value

Returns true if the first of two OracleDate values is greater than or equal to the second; otherwise, returns false.

Remarks

The following rules apply to the behavior of this method.

LessThan

This method determines if the first of two OracleDate values is less than the second.

Declaration
// C#
public static bool LessThan(OracleDate value1, OracleDate value2);
Parameters
Return Value

Returns true if the first of two OracleDate values is less than the second. Otherwise, returns false.

Remarks

The following rules apply to the behavior of this method.

LessThanOrEqual

This method determines if the first of two OracleDate values is less than or equal to the second.

Declaration
// C#
public static bool LessThanOrEqual(OracleDate value1, OracleDate value2);
Parameters
Return Value

Returns true if the first of two OracleDate values is less than or equal to the second; otherwise, returns false.

Remarks

The following rules apply to the behavior of this method.

NotEquals

This method determines if two OracleDate values are not equal.

Declaration
// C#
public static bool NotEquals(OracleDate value1, OracleDate value2);
Parameters
Return Value

Returns true if two OracleDate values are not equal; otherwise, returns false.

Remarks

The following rules apply to the behavior of this method.

GetSysDate

This method gets an OracleDate structure that represents the current date and time.

Declaration
// C#
public static OracleDate GetSysDate ();
Return Value

An OracleDate structure that represents the current date and time.

See Also:

Parse

This method gets an OracleDate structure and sets its value for date and time using the supplied string.

Declaration
// C#
public static OracleDate Parse (string dateStr);
Parameters
Return Value

An OracleDate structure.

Exceptions

ArgumentException - The dateStr is an invalid string representation of an Oracle DATE or the dateStr is not in the date format specified by the thread's OracleGlobalization.DateFormat property, which represents Oracle's NLS_DATE_FORMAT parameter.

ArgumentNullException - The dateStr is null.

Remarks

The names and abbreviations used for months and days are in the language specified by the DateLanguage and Calendar properties of the thread's OracleGlobalization object. If any of the thread's globalization properties are set to null or an empty string, the client computer's settings are used.

Example
// C#
// Set the nls_date_format for the Parse() method
OracleGlobalization og = OracleGlobalization.GetClientInfo();
og.DateFormat = "YYYY-MON-DD";
OracleGlobalization.SetThreadInfo(og);

// construct OracleDate from a string using the DateFormat specified.
OracleDate od = OracleDate.Parse("1999-NOV-11");

// Set the nls_date_format for the ToString() method
og.DateFormat = "DD-MON-YYYY";
OracleGlobalization.SetThreadInfo(og);

Console.WriteLine(od.ToString()); // Prints 11-NOV-1999

See Also:

OracleDate Static Operators

The OracleDate static operators are listed in Table 5-23.

Table 5-23 OracleDate Static Operators  
Operator Description

operator ==

Determines if two OracleDate values are the same

operator >

Determines if the first of two OracleDate values is greater than the second

operator >=

Determines if the first of two OracleDate values is greater than or equal to the second

operator !=

Determines if the two OracleDate values are not equal

operator <

Determines if the first of two OracleDate values is less than the second

operator <=

Determines if the first of two OracleDate values is less than or equal to the second

See Also:

operator ==

This method determines if two OracleDate values are the same.

Declaration
// C#
public static bool operator == (OracleDate value1, OracleDate value2);
Parameters
Return Value

Returns true if they are the same; otherwise, returns false.

Remarks

The following rules apply to the behavior of this method.

operator >

This method determines if the first of two OracleDate values is greater than the second.

Declaration
// C#
public static bool operator > (OracleDate value1, OracleDate value2);
Parameters
Return Value

Returns true if the first of two OracleDate values is greater than the second; otherwise, returns false.

Remarks

The following rules apply to the behavior of this method.

operator >=

This method determines if the first of two OracleDate values is greater than or equal to the second.

Declaration
// C#
public static bool operator >= (OracleDate value1, OracleDate value2);
Parameters
Return Value

Returns true if the first of two OracleDate values is greater than or equal to the second; otherwise, returns false.

Remarks

The following rules apply to the behavior of this method.

operator !=

This method determines if the two OracleDate values are not equal.

Declaration
// C#
public static bool operator != (OracleDate value1, OracleDate value2);
Parameters
Return Value

Returns true if the two OracleDate values are not equal; otherwise, returns false.

Remarks

The following rules apply to the behavior of this method.

operator <

This method determines if the first of two OracleDate values is less than the second.

Declaration
// C#
public static bool operator < (OracleDate value1, OracleDate value2);
Parameters
Return Value

Returns true if the first of two OracleDate values is less than the second; otherwise, returns false.

Remarks

The following rules apply to the behavior of this method.

operator <=

This method determines if the first of two OracleDate values is less than or equal to the second.

Declaration
// C#
public static bool operator <= (OracleDate value1, OracleDate value2);
Parameters
Return Value

Returns true if the first of two OracleDate values is less than or equal to the second; otherwise, returns false.

Remarks

The following rules apply to the behavior of this method.

OracleDate Static Type Conversions

The OracleDate static type conversions are listed in Table 5-24.

Table 5-24 OracleDate Static Type Conversions  
Operator Description

explicit operator DateTime

Converts a structure to a DateTime structure

explicit operator OracleDate

Converts a structure to an OracleDate structure (Overloaded)

See Also:

explicit operator DateTime

This method converts an OracleDate structure to a DateTime structure.

Declaration
// C#
public static explicit operator DateTime(OracleDate val);
Parameters
Return Value

A DateTime structure.

See Also:

explicit operator OracleDate

explicit operator OracleDate converts the provided structure to a OracleDate structure.

Overload List:

explicit operator OracleDate(DateTime)

This method converts a DateTime structure to an OracleDate structure.

Declaration
// C#
public static explicit operator OracleDate(DateTime dt);
Parameters
Return Value

An OracleDate structure.

See Also:

explicit operator OracleDate(OracleTimeStamp)

This method converts an OracleTimeStamp structure to an OracleDate structure.

Declaration
// C#
public explicit operator OracleDate(OracleTimeStamp ts);
Parameters
Return Value

The returned OracleDate structure contains the date and time in the OracleTimeStamp structure.

Remarks

The precision of the OracleTimeStamp value can be lost during the conversion.

If the OracleTimeStamp structure has a null value, the returned OracleDate structure also has a null value.

See Also:

explicit operator OracleDate(string)

This method converts the supplied string to an OracleDate structure.

Declaration
// C#
public explicit operator OracleDate (string dateStr);
Parameters
Return Value

The returned OracleDate structure contains the date and time in the string dateStr.

Exceptions

ArgumentNullException - The dateStr is null.

ArgumentException - This exception is thrown if any of the following conditions exist:

Remarks

The names and abbreviations used for months and days are in the language specified by the DateLanguage and Calendar properties of the thread's OracleGlobalization object. If any of the thread's globalization properties are set to null or an empty string, the client computer's settings are used.

Example
// C#
// Set the nls_date_format for the Parse() method
OracleGlobalization og = OracleGlobalization.GetClientInfo();
og.DateFormat = "YYYY-MON-DD";
OracleGlobalization.SetThreadInfo(og);

// construct OracleDate from a string using the DateFormat specified.
OracleDate od = (OracleDate) "1999-NOV-11";

// Set the nls_date_format for the ToString() method
og.DateFormat = "DD-MON-YYYY";
OracleGlobalization.SetThreadInfo(og);

Console.WriteLine(od.ToString()); // Prints 11-NOV-1999

See Also:

OracleDate Properties

The OracleDate properties are listed in Table 5-25.

Table 5-25 OracleDate Properties  
Properties Description

BinData

Gets an array of bytes that represents an Oracle DATE in Oracle internal format

Day

Gets the day component of an OracleDate method

IsNull

Indicates whether the current instance has a null value

Hour

Gets the hour component of an OracleDate

Minute

Gets the minute component of an OracleDate

Month

Gets the month component of an OracleDate

Second

Gets the second component of an OracleDate

Value

Gets the date and time that is stored in the OracleDate structure

Year

Gets the year component of an OracleDate

See Also:

BinData

This property gets a array of bytes that represents an Oracle DATE in Oracle internal format.

Declaration
// C#
public byte[] BinData{get;}
Property Value

An array of bytes.

Exceptions

OracleNullValueException - OracleDate has a null value.

See Also:

Day

This property gets the day component of an OracleDate.

Declaration
// C#
public int Day{get;}
Property Value

A number that represents the day. Range of Day is (1 to 31).

Exceptions

OracleNullValueException - OracleDate has a null value.

See Also:

IsNull

This property indicates whether the current instance has a null value.

Declaration
// C#
public bool IsNull{get;}
Property Value

Returns true if the current instance has a null value; otherwise, returns false.

See Also:

Hour

This property gets the hour component of an OracleDate.

Declaration
// C#
public int Hour {get;}
Property Value

A number that represents Hour. Range of Hour is (0 to 23).

Exceptions

OracleNullValueException - OracleDate has a null value.

See Also:

Minute

This property gets the minute component of an OracleDate.

Declaration
// C#
public int Minute {get;}
Property Value

A number that represents Minute. Range of Minute is (0 to 59).

Exceptions

OracleNullValueException - OracleDate has a null value.

See Also:

Month

This property gets the month component of an OracleDate.

Declaration
// C#
public int Month {get;}
Property Value

A number that represents Month. Range of Month is (1 to 12).

Exceptions

OracleNullValueException - OracleDate has a null value.

See Also:

Second

This property gets the second component of an OracleDate.

Declaration
// C#
public int Second {get;}
Property Value

A number that represents Second. Range of Second is (0 to 59).

Exceptions

OracleNullValueException - OracleDate has a null value.

See Also:

Value

This property specifies the date and time that is stored in the OracleDate structure.

Declaration
// C#
public DateTime Value {get;}
Property Value

A DateTime.

Exceptions

OracleNullValueException - OracleDate has a null value.

See Also:

Year

This property gets the year component of an OracleDate.

Declaration
// C#
public int Year {get;}
Property Value

A number that represents Year. Range of Year is (-4712 to 9999).

Exceptions

OracleNullValueException - OracleDate has a null value.

See Also:

OracleDate Methods

The OracleDate methods are listed in Table 5-26.

Table 5-26 OracleDate Methods  
Methods Description

CompareTo

Compares the current OracleDate instance to an object, and returns an integer that represents their relative values

Equals

Determines whether an object has the same date and time as the current OracleDate instance (Overloaded)

GetHashCode

Returns a hash code for the OracleDate instance

GetDaysBetween

Calculates the number of days between the current OracleDate instance and an OracleDate structure

GetType

Inherited from Object

ToOracleTimeStamp

Converts the current OracleDate structure to an OracleTimeStamp structure

ToString

Converts the current OracleDate structure to a string

See Also:

CompareTo

This method compares the current OracleDate instance to an object, and returns an integer that represents their relative values.

Declaration
// C#
public int CompareTo(object obj);
Parameters
Return Value

The method returns:

Implements

IComparable

Exceptions

ArgumentException - The obj parameter is not an instance of OracleDate.

Remarks

The following rules apply to the behavior of this method.

Equals

This method determines whether an object has the same date and time as the current OracleDate instance.

Declaration
// C#
public override bool Equals( object obj);
Parameters
Return Value

Returns true if obj has the same type as the current instance and represents the same date and time; otherwise returns false.

Remarks

The following rules apply to the behavior of this method.

GetHashCode

Overrides Object

This method returns a hash code for the OracleDate instance.

Declaration
// C#
public override int GetHashCode();
Return Value

A number that represents the hash code.

See Also:

GetDaysBetween

This method calculates the number of days between the current OracleDate instance and the supplied OracleDate structure.

Declaration
// C#
public int GetDaysBetween (OracleDate val);
Parameters
Return Value

The number of days between the current OracleDate instance and the OracleDate structure.

Exceptions

OracleNullValueException - The current instance or the supplied OracleDate structure has a null value.

See Also:

ToOracleTimeStamp

This method converts the current OracleDate structure to an OracleTimeStamp structure.

Declaration
// C#
public OracleTimeStamp ToOracleTimeStamp();
Return Value

An OracleTimeStamp structure.

Remarks

The returned OracleTimeStamp structure has date and time in the current instance.

If the OracleDate instance has a null value, the returned OracleTimeStamp structure has a null value.

See Also:

ToString

Overrides ValueType

This method converts the current OracleDate structure to a string.

Declaration
// C#
public override string ToString();
Return Value

A string.

Remarks

The returned value is a string representation of the OracleDate in the format specified by the thread's OracleGlobalization.DateFormat property. The names and abbreviations used for months and days are in the language specified by the thread's OracleGlobalization.DateLanguage and OracleGlobalization.Calendar properties. If any of the thread's globalization properties are set to null or an empty string, the client computer's settings are used.

Example
// C#
// Set the nls_date_format for the Parse() method
OracleGlobalization og = OracleGlobalization.GetClientInfo();
og.DateFormat = "YYYY-MON-DD";
OracleGlobalization.SetThreadInfo(og);

// construct OracleDate from a string using the DateFormat specified.
OracleDate od = new OracleDate("1999-NOV-11");

// Set the nls_date_format for the ToString() method
og.DateFormat = "DD-MON-YYYY";
OracleGlobalization.SetThreadInfo(og);

Console.WriteLine(od.ToString()); // Prints 11-NOV-1999


See Also:


Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 2002, 2003 Oracle Corporation.

All Rights Reserved.
Go To Table Of Contents
Contents
Go To Index
Index