| Oracle® Data Provider for .NET Developer's Guide Release 9.2.0.4 Part Number B10961-01 |
|
Oracle.DataAccess.Types Namespace (ODP.NET Types), 3 of 19
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.
Object
ValueType
OracleDate
// C# public struct OracleDate : IComparable
All public static methods are thread-safe, although instance methods do not guarantee thread safety.
// 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.");
Namespace: Oracle.DataAccess.Types
Assembly: Oracle.DataAccess.dll
OracleDate members are listed in the following tables:
OracleDate constructors are listed in Table 5-14
| Constructor | Description |
|---|---|
|
Instantiates a new instance of OracleDate structure (Overloaded) |
The OracleDate static fields are listed in Table 5-15.
The OracleDate static methods are listed in Table 5-16.
The OracleDate static operators are listed in Table 5-17.
The OracleDate static type conversions are listed in Table 5-18.
| Operator | Description |
|---|---|
|
Converts a structure to a |
|
|
Converts a structure to an |
The OracleDate properties are listed in Table 5-19.
The OracleDate methods are listed in Table 5-20.
The OracleDate constructors instantiates a new instance of the OracleDate structure.
This constructor creates a new instance of the OracleDate structure and sets its value for date and time using the supplied DateTime value.
This constructor creates a new instance of the OracleDate structure and sets its value using the supplied string.
This constructor creates a new instance of the OracleDate structure and set its value for date using the supplied year, month, and day.
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.
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.
This constructor creates a new instance of the OracleDate structure and sets its value for date and time using the supplied DateTime value.
// C# public OracleDate (DateTime dt);
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.
This constructor creates a new instance of the OracleDate structure and sets its value using the supplied string.
// C# public OracleDate (string dateStr);
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.
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.
// 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:
|
This constructor creates a new instance of the OracleDate structure and set its value for date using the supplied year, month, and day.
// C# public OracleDate (int year, int month, int day);
year
The supplied year. Range of year is (-4712 to 9999).
month
The supplied month. Range of month is (1 to 12).
day
The supplied day. Range of day is (1 to 31).
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).
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.
// C# public OracleDate (int year, int month, int day, int hour, int minute, int second);
year
The supplied year. Range of year is (-4712 to 9999).
month
The supplied month. Range of month is (1 to 12).
day
The supplied day. Range of day is (1 to 31).
hour
The supplied hour. Range of hour is (0 to 23).
minute
The supplied minute. Range of minute is (0 to 59).
second
The supplied second. Range of second is (0 to 59).
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).
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.
// C# public OracleDate(byte [] bytes);
ArgumentException - bytes is null or bytes is not in internal Oracle DATE format or bytes is not a valid Oracle DATE.
The OracleDate static fields are listed in Table 5-21.
This static field represents the maximum valid date for an OracleDate structure, which is December 31, 9999 23:59:59.
// C# public static readonly OracleDate MaxValue;
This static field represents the minimum valid date for an OracleDate structure, which is January 1, -4712.
// C# public static readonly OracleDate MinValue;
This static field represents a null value that can be assigned to the value of an OracleDate instance.
// C# public static readonly OracleDate Null;
The OracleDate static methods are listed in Table 5-22.
Overloads Object
This method determines if two OracleDate values are equal.
// C# public static bool Equals(OracleDate value1, OracleDate value2);
Returns true if two OracleDate values are equal; otherwise, returns false.
The following rules apply to the behavior of this method.
OracleDate that has a value compares greater than an OracleDate that has a null value.
OracleDates that contain a null value are equal.
This method determines if the first of two OracleDate values is greater than the second.
// C# public static bool GreaterThan(OracleDate value1, OracleDate value2);
Returns true if the first of two OracleDate values is greater than the second; otherwise, returns false.
The following rules apply to the behavior of this method.
OracleDate that has a value compares greater than an OracleDate that has a null value.
OracleDates that contain a null value are equal.
This method determines if the first of two OracleDate values is greater than or equal to the second.
// C# public static bool GreaterThanOrEqual(OracleDate value1, OracleDate value2);
Returns true if the first of two OracleDate values is greater than or equal to the second; otherwise, returns false.
The following rules apply to the behavior of this method.
OracleDate that has a value compares greater than an OracleDate that has a null value.
OracleDates that contain a null value are equal.
This method determines if the first of two OracleDate values is less than the second.
// C# public static bool LessThan(OracleDate value1, OracleDate value2);
Returns true if the first of two OracleDate values is less than the second. Otherwise, returns false.
The following rules apply to the behavior of this method.
OracleDate that has a value compares greater than an OracleDate that has a null value.
OracleDates that contain a null value are equal.
This method determines if the first of two OracleDate values is less than or equal to the second.
// C# public static bool LessThanOrEqual(OracleDate value1, OracleDate value2);
Returns true if the first of two OracleDate values is less than or equal to the second; otherwise, returns false.
The following rules apply to the behavior of this method.
OracleDate that has a value compares greater than an OracleDate that has a null value.
OracleDates that contain a null value are equal.
This method determines if two OracleDate values are not equal.
// C# public static bool NotEquals(OracleDate value1, OracleDate value2);
Returns true if two OracleDate values are not equal; otherwise, returns false.
The following rules apply to the behavior of this method.
OracleDate that has a value compares greater than an OracleDate that has a null value.
OracleDates that contain a null value are equal.
This method gets an OracleDate structure that represents the current date and time.
// C# public static OracleDate GetSysDate ();
An OracleDate structure that represents the current date and time.
This method gets an OracleDate structure and sets its value for date and time using the supplied string.
// C# public static OracleDate Parse (string dateStr);
An OracleDate structure.
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.
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.
// 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:
|
The OracleDate static operators are listed in Table 5-23.
This method determines if two OracleDate values are the same.
// C# public static bool operator == (OracleDate value1, OracleDate value2);
Returns true if they are the same; otherwise, returns false.
The following rules apply to the behavior of this method.
OracleDate that has a value compares greater than an OracleDate that has a null value.
OracleDates that contain a null value are equal.
This method determines if the first of two OracleDate values is greater than the second.
// C# public static bool operator > (OracleDate value1, OracleDate value2);
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.
OracleDate that has a value compares greater than an OracleDate that has a null value.
OracleDates that contain a null value are equal.
This method determines if the first of two OracleDate values is greater than or equal to the second.
// C# public static bool operator >= (OracleDate value1, OracleDate value2);
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.
OracleDate that has a value compares greater than an OracleDate that has a null value.
OracleDates that contain a null value are equal.
This method determines if the two OracleDate values are not equal.
// C# public static bool operator != (OracleDate value1, OracleDate value2);
Returns true if the two OracleDate values are not equal; otherwise, returns false.
The following rules apply to the behavior of this method.
OracleDate that has a value compares greater than an OracleDate that has a null value.
OracleDates that contain a null value are equal.
This method determines if the first of two OracleDate values is less than the second.
// C# public static bool operator < (OracleDate value1, OracleDate value2);
Returns true if the first of two OracleDate values is less than the second; otherwise, returns false.
The following rules apply to the behavior of this method.
OracleDate that has a value compares greater than an OracleDate that has a null value.
OracleDates that contain a null value are equal.
This method determines if the first of two OracleDate values is less than or equal to the second.
// C# public static bool operator <= (OracleDate value1, OracleDate value2);
Returns true if the first of two OracleDate values is less than or equal to the second; otherwise, returns false.
The following rules apply to the behavior of this method.
OracleDate that has a value compares greater than an OracleDate that has a null value.
OracleDates that contain a null value are equal.
The OracleDate static type conversions are listed in Table 5-24.
| Operator | Description |
|---|---|
|
Converts a structure to a |
|
|
Converts a structure to an |
This method converts an OracleDate structure to a DateTime structure.
// C# public static explicit operator DateTime(OracleDate val);
A DateTime structure.
explicit operator OracleDate converts the provided structure to a OracleDate structure.
This method converts a DateTime structure to an OracleDate structure.
This method converts an OracleTimeStamp structure to an OracleDate structure.
This method converts the supplied string to an OracleDate structure.
This method converts a DateTime structure to an OracleDate structure.
// C# public static explicit operator OracleDate(DateTime dt);
An OracleDate structure.
This method converts an OracleTimeStamp structure to an OracleDate structure.
// C# public explicit operator OracleDate(OracleTimeStamp ts);
The returned OracleDate structure contains the date and time in the OracleTimeStamp structure.
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.
This method converts the supplied string to an OracleDate structure.
// C# public explicit operator OracleDate (string dateStr);
The returned OracleDate structure contains the date and time in the string dateStr.
ArgumentNullException - The dateStr is null.
ArgumentException - This exception is thrown if any of the following conditions exist:
dateStr is an invalid string representation of an Oracle DATE.
dateStr is not in the date format specified by the thread's OracleGlobalization.DateFormat property, which represents Oracle's NLS_DATE_FORMAT parameter.
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.
// 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
The OracleDate properties are listed in Table 5-25.
This property gets a array of bytes that represents an Oracle DATE in Oracle internal format.
// C# public byte[] BinData{get;}
An array of bytes.
OracleNullValueException - OracleDate has a null value.
This property gets the day component of an OracleDate.
// C# public int Day{get;}
A number that represents the day. Range of Day is (1 to 31).
OracleNullValueException - OracleDate has a null value.
This property indicates whether the current instance has a null value.
// C# public bool IsNull{get;}
Returns true if the current instance has a null value; otherwise, returns false.
This property gets the hour component of an OracleDate.
// C# public int Hour {get;}
A number that represents Hour. Range of Hour is (0 to 23).
OracleNullValueException - OracleDate has a null value.
This property gets the minute component of an OracleDate.
// C# public int Minute {get;}
A number that represents Minute. Range of Minute is (0 to 59).
OracleNullValueException - OracleDate has a null value.
This property gets the month component of an OracleDate.
// C# public int Month {get;}
A number that represents Month. Range of Month is (1 to 12).
OracleNullValueException - OracleDate has a null value.
This property gets the second component of an OracleDate.
// C# public int Second {get;}
A number that represents Second. Range of Second is (0 to 59).
OracleNullValueException - OracleDate has a null value.
This property specifies the date and time that is stored in the OracleDate structure.
// C# public DateTime Value {get;}
A DateTime.
OracleNullValueException - OracleDate has a null value.
This property gets the year component of an OracleDate.
// C# public int Year {get;}
A number that represents Year. Range of Year is (-4712 to 9999).
OracleNullValueException - OracleDate has a null value.
The OracleDate methods are listed in Table 5-26.
This method compares the current OracleDate instance to an object, and returns an integer that represents their relative values.
// C# public int CompareTo(object obj);
The method returns:
OracleDate instance value is less than that of obj.
OracleDate instance and obj values are equal.
OracleDate instance value is greater than obj.
IComparable
ArgumentException - The obj parameter is not an instance of OracleDate.
The following rules apply to the behavior of this method.
OracleDates. For example, comparing an OracleDate instance with an OracleBinary instance is not allowed. When an OracleDate is compared with a different type, an ArgumentException is thrown.
OracleDate that has a value compares greater than an OracleDate that has a null value.
OracleDates that contain a null value are equal.
This method determines whether an object has the same date and time as the current OracleDate instance.
// C# public override bool Equals( object obj);
Returns true if obj has the same type as the current instance and represents the same date and time; otherwise returns false.
The following rules apply to the behavior of this method.
OracleDate that has a value compares greater than an OracleDate that has a null value.
OracleDates that contain a null value are equal.
Overrides Object
This method returns a hash code for the OracleDate instance.
// C# public override int GetHashCode();
A number that represents the hash code.
This method calculates the number of days between the current OracleDate instance and the supplied OracleDate structure.
// C# public int GetDaysBetween (OracleDate val);
The number of days between the current OracleDate instance and the OracleDate structure.
OracleNullValueException - The current instance or the supplied OracleDate structure has a null value.
This method converts the current OracleDate structure to an OracleTimeStamp structure.
// C# public OracleTimeStamp ToOracleTimeStamp();
An OracleTimeStamp structure.
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.
Overrides ValueType
This method converts the current OracleDate structure to a string.
// C# public override string ToString();
A string.
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.
// 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
|
|
![]() Copyright © 2002, 2003 Oracle Corporation. All Rights Reserved. |
|