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.
System.Object
System.ValueType
Oracle.DataAccess.Types.OracleDate
// ADO.NET 2.0: C# public struct OracleDate : IComparable, INullable, IXmlSerializable
All public static methods are thread-safe, although instance methods do not guarantee thread safety.
// 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); } }
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
See Also:
OracleDate
members are listed in the following tables:
OracleDate
constructors are listed in Table 14-14
Table 14-14 OracleDate Constructors
Constructor | Description |
---|---|
Instantiates a new instance of |
The OracleDate
static fields are listed in Table 14-15.
Table 14-15 OracleDate Static Fields
Field | Description |
---|---|
Represents the maximum valid date for an |
|
Represents the minimum valid date for an |
|
Represents a null value that can be assigned to the value of an |
The OracleDate
static methods are listed in Table 14-16.
Table 14-16 OracleDate Static Methods
Methods | Description |
---|---|
Determines if two |
|
Determines if the first of two |
|
Determines if the first of two |
|
Determines if the first of two |
|
Determines if the first of two |
|
Determines if two |
|
Returns an |
|
Returns an |
The OracleDate
static operators are listed in Table 14-17.
Table 14-17 OracleDate Static Operators
Operator | Description |
---|---|
Determines if two |
|
Determines if the first of two |
|
Determines if the first of two |
|
Determines if the two |
|
Determines if the first of two |
|
Determines if the first of two |
OracleDate Static Type Conversions
The OracleDate
static type conversions are listed in Table 14-18.
Table 14-18 OracleDate Static Type Conversions
Operator | Description |
---|---|
Converts a structure to a |
|
Converts a structure to an |
The OracleDate
properties are listed in Table 14-19.
Table 14-19 OracleDate Properties
Properties | Description |
---|---|
Gets an array of bytes that represents an Oracle |
|
Gets the day component of an |
|
Indicates whether or not the current instance has a null value |
|
Gets the |
|
Gets the minute component of an |
|
Gets the |
|
Gets the |
|
Gets the date and time that is stored in the |
|
Gets the |
The OracleDate
methods are listed in Table 14-20.
Table 14-20 OracleDate Methods
Methods | Description |
---|---|
Compares the current |
|
Determines whether or not an object has the same date and time as the current |
|
Returns a hash code for the |
|
Calculates the number of days between the current |
|
GetType |
Inherited from |
Converts the current |
|
Converts the current |
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.
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.
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);
dt
The provided DateTime
value.
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);
dateStr
A string that represents an Oracle DATE
.
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.
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# 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()); } }
See Also:
Oracle Database SQL Reference for further information on date format elements
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);
bytes
A byte array that represents Oracle DATE
in the internal Oracle DATE
format.
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 14-21.
Table 14-21 OracleDate Static Fields
Field | Description |
---|---|
Represents the maximum valid date for an |
|
Represents the minimum valid date for an |
|
Represents a null value that can be assigned to the value of an |
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;
The OracleDate
static methods are listed in Table 14-22.
Table 14-22 OracleDate Static Methods
Methods | Description |
---|---|
Determines if two |
|
Determines if the first of two |
|
Determines if the first of two |
|
Determines if the first of two |
|
Determines if the first of two |
|
Determines if two |
|
Returns an |
|
Returns an |
Overloads Object
This method determines if two OracleDate
values are equal.
// C# public static bool Equals(OracleDate value1, OracleDate value2);
value1
The first OracleDate
.
value2
The second OracleDate
.
Returns true
if two OracleDate
values are equal; otherwise, returns false
.
The following rules apply to the behavior of this method.
Any OracleDate
that has a value compares greater than an OracleDate
that has a null value.
Two OracleDate
s 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);
value1
The first OracleDate
.
value2
The second OracleDate
.
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.
Any OracleDate
that has a value compares greater than an OracleDate
that has a null value.
Two OracleDate
s 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);
value1
The first OracleDate
.
value2
The second OracleDate
.
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.
Any OracleDate
that has a value compares greater than an OracleDate
that has a null value.
Two OracleDate
s 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);
value1
The first OracleDate
.
value2
The second OracleDate
.
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.
Any OracleDate
that has a value compares greater than an OracleDate
that has a null value.
Two OracleDate
s 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);
value1
The first OracleDate
.
value2
The second OracleDate
.
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.
Any OracleDate
that has a value compares greater than an OracleDate
that has a null value.
Two OracleDate
s 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);
value1
The first OracleDate
.
value2
The second OracleDate
.
Returns true
if two OracleDate
values are not equal; otherwise, returns false
.
The following rules apply to the behavior of this method.
Any OracleDate
that has a value compares greater than an OracleDate
that has a null value.
Two OracleDate
s 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);
dateStr
A string that represents an Oracle DATE
.
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 the Oracle 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# 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()); } }
See Also:
Oracle Database SQL Reference for further information on datetime format elements
The OracleDate
static operators are listed in Table 14-23.
Table 14-23 OracleDate Static Operators
Operator | Description |
---|---|
Determines if two |
|
Determines if the first of two |
|
Determines if the first of two |
|
Determines if the two |
|
Determines if the first of two |
|
Determines if the first of two |
This method determines if two OracleDate
values are the same.
// C# public static bool operator == (OracleDate value1, OracleDate value2);
value1
The first OracleDate
.
value2
The second OracleDate
.
Returns true
if they are the same; otherwise, returns false
.
The following rules apply to the behavior of this method.
Any OracleDate
that has a value compares greater than an OracleDate
that has a null value.
Two OracleDate
s 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);
value1
The first OracleDate
.
value2
The second OracleDate
.
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.
Any OracleDate
that has a value compares greater than an OracleDate
that has a null value.
Two OracleDate
s 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);
value1
The first OracleDate
.
value2
The second OracleDate
.
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.
Any OracleDate
that has a value compares greater than an OracleDate
that has a null value.
Two OracleDate
s 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);
value1
The first OracleDate
.
value2
The second OracleDate
.
Returns true
if the two OracleDate
values are not equal; otherwise, returns false
.
The following rules apply to the behavior of this method.
Any OracleDate
that has a value compares greater than an OracleDate
that has a null value.
Two OracleDate
s 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);
value1
The first OracleDate
.
value2
The second OracleDate
.
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.
Any OracleDate
that has a value compares greater than an OracleDate
that has a null value.
Two OracleDate
s 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);
value1
The first OracleDate
.
value2
The second OracleDate
.
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.
Any OracleDate
that has a value compares greater than an OracleDate
that has a null value.
Two OracleDate
s that contain a null value are equal.
The OracleDate
static type conversions are listed in Table 14-24.
Table 14-24 OracleDate Static Type Conversions
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);
val
An OracleDate
structure.
A DateTime
structure.
explicit
operator
OracleDate
converts the provided structure to an OracleDate
structure.
explicit operator OracleDate(DateTime)
This method converts a DateTime
structure to an OracleDate
structure.
explicit operator OracleDate(OracleTimeStamp)
This method converts an OracleTimeStamp
structure to an OracleDate
structure.
explicit operator OracleDate(string)
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);
dt
A DateTime
structure.
An OracleDate
structure.
This method converts an OracleTimeStamp
structure to an OracleDate
structure.
// C#
public explicit operator OracleDate(OracleTimeStamp ts);
ts
OracleTimeStamp
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);
dateStr
A string representation of an Oracle DATE
.
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:
The dateStr
is an invalid string representation of an Oracle DATE
.
The dateStr
is not in the date format specified by the thread's OracleGlobalization
.DateFormat
property, which represents the Oracle 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# 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()); } }
The OracleDate
properties are listed in Table 14-25.
Table 14-25 OracleDate Properties
Properties | Description |
---|---|
Gets an array of bytes that represents an Oracle |
|
Gets the day component of an |
|
Indicates whether or not the current instance has a null value |
|
Gets the |
|
Gets the minute component of an |
|
Gets the |
|
Gets the |
|
Gets the date and time that is stored in the |
|
Gets the |
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 or not 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.
The OracleDate
methods are listed in Table 14-26.
Table 14-26 OracleDate Methods
Methods | Description |
---|---|
Compares the current |
|
Determines whether or not an object has the same date and time as the current |
|
Returns a hash code for the |
|
Calculates the number of days between the current |
|
GetType |
Inherited from |
Converts the current |
|
Converts the current |
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);
obj
An object.
The method returns:
Less than zero: if the current OracleDate
instance value is less than that of obj
.
Zero: if the current OracleDate
instance and obj
values are equal.
Greater than zero: if the current 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.
The comparison must be between OracleDate
s. 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.
Any OracleDate
that has a value compares greater than an OracleDate
that has a null value.
Two OracleDate
s that contain a null value are equal.
This method determines whether or not an object has the same date and time as the current OracleDate
instance.
// C#
public override bool Equals( object obj);
obj
An object.
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.
Any OracleDate
that has a value compares greater than an OracleDate
that has a null value.
Two OracleDate
s 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);
val
An OracleDate
structure.
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# 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()); } }