Skip Headers
Oracle® Data Provider for .NET Developer's Guide
11g Release 2 (11.2.0.2)

Part Number E18754-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

OracleDate Structure

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

Class Inheritance

System.Object

  System.ValueType

    Oracle.DataAccess.Types.OracleDate

Declaration

// ADO.NET 2.0: C#
public struct OracleDate : IComparable, INullable, IXmlSerializable

Thread Safety

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

Example

// C#
 
using System;
using Oracle.DataAccess.Types;
using Oracle.DataAccess.Client;
 
class OracleDateSample
{
  static void Main(string[] args)
  {
    // Initialize the dates to the lower and upper boundaries
    OracleDate date1 = OracleDate.MinValue;
    OracleDate date2 = OracleDate.MaxValue;
    OracleDate date3 = new OracleDate(DateTime.MinValue);
    OracleDate date4 = new OracleDate(DateTime.MaxValue);
    
    // Set the thread's DateFormat for output
    OracleGlobalization info = OracleGlobalization.GetClientInfo();
    info.DateFormat = "DD-MON-YYYY BC";
    OracleGlobalization.SetThreadInfo(info);
 
    // Print the lower and upper boundaries
    Console.WriteLine("OracleDate ranges from\n{0}\nto\n{1}\n", 
      date1, date2);
    Console.WriteLine(".NET DateTime ranges from\n{0}\nto\n{1}\n", 
      date3, date4);
  }
}

Requirements

Namespace: Oracle.DataAccess.Types

Assembly: Oracle.DataAccess.dll

ODP.NET Version: ODP.NET for .NET Framework 2.0 or ODP.NET for .NET Framework 4


OracleDate Members

OracleDate members are listed in the following tables:

OracleDate Constructors

OracleDate constructors are listed in Table 14-14

Table 14-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 14-15.

Table 14-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 14-16.

Table 14-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 14-17.

Table 14-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 14-18.

Table 14-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 14-19.

Table 14-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 or not 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 14-20.

Table 14-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 or not 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 System.Object

ToOracleTimeStamp

Converts the current OracleDate structure to an OracleTimeStamp structure

ToString

Converts the current OracleDate structure to a string



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.

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 the Oracle 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#
 
using System;
using Oracle.DataAccess.Types;
using Oracle.DataAccess.Client;
 
class OracleDateSample
{
  static void Main(string[] args)
  {
    // Set the thread's DateFormat for the OracleDate constructor
    OracleGlobalization info = OracleGlobalization.GetClientInfo();
    info.DateFormat = "YYYY-MON-DD";
    OracleGlobalization.SetThreadInfo(info);
    
    // construct OracleDate from a string using the DateFormat specified.
    OracleDate date = new OracleDate("1999-DEC-01");
    
    // Set a different DateFormat for the thread
    info.DateFormat = "MM/DD/YYYY";
    OracleGlobalization.SetThreadInfo(info);
 
    // Print "12/01/1999"
    Console.WriteLine(date.ToString()); 
  }
}

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).

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).

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.


OracleDate Static Fields

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

Table 14-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


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;

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;

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;

OracleDate Static Methods

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

Table 14-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


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.

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 the Oracle 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#
 
using System;
using Oracle.DataAccess.Types;
using Oracle.DataAccess.Client;
 
class ParseSample
{
  static void Main(string[] args)
  {
    // Set the thread's DateFormat for the OracleDate constructor
    OracleGlobalization info = OracleGlobalization.GetClientInfo();
    info.DateFormat = "YYYY-MON-DD";
    OracleGlobalization.SetThreadInfo(info);
    
    // Construct OracleDate from a string using the DateFormat specified
    OracleDate date = OracleDate.Parse("1999-DEC-01");
    
    // Set a different DateFormat on the thread for ToString() 
    info.DateFormat = "MM-DD-YY";
    OracleGlobalization.SetThreadInfo(info);
 
    // Print "12-01-1999"
    Console.WriteLine(date.ToString()); 
  }
}

OracleDate Static Operators

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

Table 14-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


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 14-24.

Table 14-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)


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.

explicit operator OracleDate

explicit operator OracleDate converts the provided structure to an 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.

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.

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#
 
using System;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
 
class OracleDateSample
{
  static void Main(string[] args)
  {
    // Set the thread's DateFormat to a specific format
    OracleGlobalization info = OracleGlobalization.GetClientInfo();
    info.DateFormat = "YYYY-MON-DD";
    OracleGlobalization.SetThreadInfo(info);
    
    // Construct OracleDate from a string using the DateFormat specified
    OracleDate date = (OracleDate)"1999-DEC-01";
    
    // Set a different DateFormat on the thread for ToString() 
    info.DateFormat = "MON DD YY";
    OracleGlobalization.SetThreadInfo(info);
 
    // Prints "DEC 01 99"
    Console.WriteLine(date.ToString()); 
  }
}

OracleDate Properties

The OracleDate properties are listed in Table 14-25.

Table 14-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 or not 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


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.

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.

IsNull

This property indicates whether or not 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.

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.

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.

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.

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.

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.

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.


OracleDate Methods

The OracleDate methods are listed in Table 14-26.

Table 14-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 or not 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 System.Object

ToOracleTimeStamp

Converts the current OracleDate structure to an OracleTimeStamp structure

ToString

Converts the current OracleDate structure to a string


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 or not 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.

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.

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.

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#
 
using System;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
 
class ToStringSample
{
  static void Main(string[] args)
  {
    // Set the thread's DateFormat to a specific format
    OracleGlobalization info = OracleGlobalization.GetClientInfo();
    info.DateFormat = "YYYY-MON-DD";
    OracleGlobalization.SetThreadInfo(info);
    
    // Construct OracleDate from a string using the DateFormat specified
    OracleDate date = (OracleDate)"1999-DEC-01";
    
    // Set a different DateFormat on the thread for ToString() 
    info.DateFormat = "YYYY/MM/DD";
    OracleGlobalization.SetThreadInfo(info);
 
    // Prints "1999/12/01"
    Console.WriteLine(date.ToString()); 
  }
}