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

Part Number E23174-02
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

OracleTimeStamp Structure

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

Class Inheritance

System.Object

  System.ValueType

    Oracle.DataAccess.Types.OracleTimeStamp

Declaration

// ADO.NET 2.0: C#public struct OracleTimeStamp : 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;
 
class OracleTimeStampSample
{
  static void Main()
  {
    OracleTimeStamp tsCurrent1 = OracleTimeStamp.GetSysDate();
    OracleTimeStamp tsCurrent2 = DateTime.Now;
    
    // Calculate the difference between tsCurrent1 and tsCurrent2
    OracleIntervalDS idsDiff = tsCurrent2.GetDaysBetween(tsCurrent1);
    
    // Calculate the difference using AddNanoseconds()
    int nanoDiff = 0;
    while (tsCurrent2 > tsCurrent1)
    {
      nanoDiff += 10;
      tsCurrent1 = tsCurrent1.AddNanoseconds(10);
    }
    Console.WriteLine("idsDiff.Nanoseconds = " + idsDiff.Nanoseconds);
    Console.WriteLine("nanoDiff = " + nanoDiff);
  }
}

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


OracleTimeStamp Members

OracleTimeStamp members are listed in the following tables:

OracleTimeStamp Constructors

OracleTimeStamp constructors are listed in Table 14-87

Table 14-87 OracleTimeStamp Constructors

Constructor Description

OracleTimeStamp Constructors

Instantiates a new instance of OracleTimeStamp structure (Overloaded)


OracleTimeStamp Static Fields

The OracleTimeStamp static fields are listed in Table 14-88.

Table 14-88 OracleTimeStamp Static Fields

Field Description

MaxValue

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

MinValue

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

Null

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


OracleTimeStamp Static Methods

The OracleTimeStamp static methods are listed in Table 14-89.

Table 14-89 OracleTimeStamp Static Methods

Methods Description

Equals

Determines if two OracleTimeStamp values are equal (Overloaded)

GreaterThan

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

GreaterThanOrEqual

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

LessThan

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

LessThanOrEqual

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

NotEquals

Determines if two OracleTimeStamp values are not equal

GetSysDate

Gets an OracleTimeStamp structure that represents the current date and time

Parse

Gets an OracleTimeStamp structure and sets its value using the supplied string

SetPrecision

Returns a new instance of an OracleTimeStamp with the specified fractional second precision


OracleTimeStamp Static Operators

The OracleTimeStamp static operators are listed in Table 14-90.

Table 14-90 OracleTimeStamp Static Operators

Operator Description

operator +

Adds the supplied instance value to the supplied OracleTimeStamp and returns a new OracleTimeStamp structure (Overloaded)

operator ==

Determines if two OracleTimeStamp values are equal

operator >

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

operator >=

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

operator !=

Determines if the two OracleTimeStamp values are not equal

operator <

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

operator <=

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

operator -

Subtracts the supplied instance value from the supplied OracleTimeStamp and returns a new OracleTimeStamp structure (Overloaded)


OracleTimeStamp Static Type Conversions

The OracleTimeStamp static type conversions are listed in Table 14-91.

Table 14-91 OracleTimeStamp Static Type Conversions

Operator Description

explicit operator OracleTimeStamp

Converts an instance value to an OracleTimeStamp structure (Overloaded)

implicit operator OracleTimeStamp

Converts an instance value to an OracleTimeStamp structure (Overloaded)

explicit operator DateTime

Converts an OracleTimeStamp value to a DateTime structure


OracleTimeStamp Properties

The OracleTimeStamp properties are listed in Table 14-92.

Table 14-92 OracleTimeStamp Properties

Properties Description

BinData

Returns an array of bytes that represents an Oracle TIMESTAMP in Oracle internal format

Day

Specifies the day component of an OracleTimeStamp

IsNull

Indicates whether or not the OracleTimeStamp instance has a null value

Hour

Specifies the hour component of an OracleTimeStamp

Millisecond

Specifies the millisecond component of an OracleTimeStamp

Minute

Specifies the minute component of an OracleTimeStamp

Month

Specifies the month component of an OracleTimeStamp

Nanosecond

Specifies the nanosecond component of an OracleTimeStamp

Second

Specifies the second component of an OracleTimeStamp

Value

Specifies the date and time that is stored in the OracleTimeStamp structure

Year

Specifies the year component of an OracleTimeStamp


OracleTimeStamp Methods

The OracleTimeStamp methods are listed in Table 14-93.

Table 14-93 OracleTimeStamp Methods

Methods Description

AddDays

Adds the supplied number of days to the current instance

AddHours

Adds the supplied number of hours to the current instance

AddMilliseconds

Adds the supplied number of milliseconds to the current instance

AddMinutes

Adds the supplied number of minutes to the current instance

AddMonths

Adds the supplied number of months to the current instance

AddNanoseconds

Adds the supplied number of nanoseconds to the current instance

AddSeconds

Adds the supplied number of seconds to the current instance

AddYears

Adds the supplied number of years to the current instance

CompareTo

Compares the current OracleTimeStamp 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 OracleTimeStamp instance (Overloaded)

GetHashCode

Returns a hash code for the OracleTimeStamp instance

GetDaysBetween

Subtracts an OracleTimeStamp value from the current instance and returns an OracleIntervalDS that represents the time difference between the supplied OracleTimeStamp and the current instance

GetYearsBetween

Subtracts value1 from the current instance and returns an OracleIntervalYM that represents the difference between value1 and the current instance using OracleIntervalYM

GetType

Inherited from System.Object

ToOracleDate

Converts the current OracleTimeStamp structure to an OracleDate structure

ToOracleTimeStampLTZ

Converts the current OracleTimeStamp structure to an OracleTimeStampLTZ structure

ToOracleTimeStampTZ

Converts the current OracleTimeStamp structure to an OracleTimeStampTZ structure

ToString

Converts the current OracleTimeStamp structure to a string



OracleTimeStamp Constructors

The OracleTimeStamp constructors create new instances of the OracleTimeStamp structure.

Overload List:

OracleTimeStamp(DateTime)

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

Declaration

// C#
public OracleTimeStamp (DateTime dt);

Parameters

Exceptions

ArgumentException - The dt parameter cannot be used to construct a valid OracleTimeStamp.

OracleTimeStamp(string)

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

Declaration

// C#
public OracleTimeStamp (string tsStr);

Parameters

Exceptions

ArgumentException - The tsStr value is an invalid string representation of an Oracle TIMESTAMP or the supplied tsStr is not in the timestamp format specified by the OracleGlobalization.TimeStampFormat property of the thread, which represents the Oracle NLS_TIMESTAMP_FORMAT parameter.

ArgumentNullException - The tsStr value 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 OracleTimeStampSample
{
  static void Main()
  {
    // Set the nls_timestamp_format for the OracleTimeStamp(string) 
    // constructor
    OracleGlobalization info = OracleGlobalization.GetClientInfo();
    info.TimeStampFormat = "DD-MON-YYYY HH:MI:SS.FF AM";
    OracleGlobalization.SetThreadInfo(info);
    
    // construct OracleTimeStamp from a string using the format specified.
    OracleTimeStamp ts = new OracleTimeStamp("11-NOV-1999 11:02:33.444 AM");
    
    // Set the nls_timestamp_format for the ToString() method
    info.TimeStampFormat = "YYYY-MON-DD HH:MI:SS.FF AM";
    OracleGlobalization.SetThreadInfo(info);
 
    // Prints "1999-NOV-11 11:02:33.444000000 AM"
    Console.WriteLine(ts.ToString());    
  }
}

OracleTimeStamp(int, int, int)

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

Declaration

// C#
public OracleTimeStamp(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 OracleTimeStamp (that is, the day is out of range for the month).

OracleTimeStamp(int, int, int, int, int, int)

This constructor creates a new instance of the OracleTimeStamp structure and sets its value for date and time using year, month, day, hour, minute, and second.

Declaration

// C#
public OracleTimeStamp (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 OracleTimeStamp (that is, the day is out of range for the month).

OracleTimeStamp(int, int, int, int, int, int, double)

This constructor creates a new instance of the OracleTimeStamp structure and sets its value for date and time using year, month, day, hour, minute, second, and millisecond.

Declaration

// C#
public OracleTimeStamp(int year, int month, int day, int hour,
   int minute,  int second, double millisecond);
 

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 OracleTimeStamp (that is, the day is out of range for the month).

OracleTimeStamp(int, int, int, int, int, int, int)

This constructor creates a new instance of the OracleTimeStamp structure and sets its value for date and time using year, month, day, hour, minute, second, and nanosecond.

Declaration

// C#
public OracleTimeStamp (int year, int month, int day, int hour, 
   int minute, int second, int nanosecond);
   

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 OracleTimeStamp (that is, the day is out of range for the month).

OracleTimeStamp(byte [ ])

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

Declaration

// C#
public OracleTimeStamp (byte[] bytes);

Parameters

Exceptions

ArgumentException - bytes is not in an internal Oracle TIMESTAMP format or bytes is not a valid Oracle TIMESTAMP.

ArgumentNullException - bytes is null.


OracleTimeStamp Static Fields

The OracleTimeStamp static fields are listed in Table 14-94.

Table 14-94 OracleTimeStamp Static Fields

Field Description

MaxValue

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

MinValue

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

Null

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


MaxValue

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

Declaration

// C#
public static readonly OraTimestamp MaxValue;

MinValue

This static field represents the minimum valid date and time for an OracleTimeStamp structure, which is January 1, -4712 0:0:0.

Declaration

// C#
public static readonly OracleTimeStamp MinValue;

Null

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

Declaration

// C#
public static readonly OracleTimeStamp Null;

OracleTimeStamp Static Methods

The OracleTimeStamp static methods are listed in Table 14-95.

Table 14-95 OracleTimeStamp Static Methods

Methods Description

Equals

Determines if two OracleTimeStamp values are equal (Overloaded)

GreaterThan

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

GreaterThanOrEqual

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

LessThan

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

LessThanOrEqual

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

NotEquals

Determines if two OracleTimeStamp values are not equal

GetSysDate

Gets an OracleTimeStamp structure that represents the current date and time

Parse

Gets an OracleTimeStamp structure and sets its value using the supplied string

SetPrecision

Returns a new instance of an OracleTimeStamp with the specified fractional second precision


Equals

This static method determines if two OracleTimeStamp values are equal.

Declaration

// C#
public static bool Equals(OracleTimeStamp value1, OracleTimeStamp value2);

Parameters

Return Value

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

Remarks

The following rules apply to the behavior of this method.

GreaterThan

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

Declaration

// C#
public static bool GreaterThan(OracleTimeStamp value1, 
   OracleTimeStamp value2);

Parameters

Return Value

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

Remarks

The following rules apply to the behavior of this method.

GreaterThanOrEqual

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

Declaration

// C#
public static bool GreaterThanOrEqual(OracleTimeStamp value1, 
     OracleTimeStamp value2);

Parameters

Return Value

Returns true if the first of two OracleTimeStamp 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 static method determines if the first of two OracleTimeStamp values is less than the second.

Declaration

// C#
public static bool LessThan(OracleTimeStamp value1, 
   OracleTimeStamp value2);

Parameters

Return Value

Returns true if the first of two OracleTimeStamp values is less than the second. Returns false otherwise.

Remarks

The following rules apply to the behavior of this method.

LessThanOrEqual

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

Declaration

// C#
public static bool LessThanOrEqual(OracleTimeStamp value1, 
     OracleTimeStamp value2);

Parameters

Return Value

Returns true if the first of two OracleTimeStamp values is less than or equal to the second. Returns false otherwise.

Remarks

The following rules apply to the behavior of this method.

NotEquals

This static method determines if two OracleTimeStamp values are not equal.

Declaration

// C#
public static bool NotEquals(OracleTimeStamp value1, 
   OracleTimeStamp value2);

Parameters

Return Value

Returns true if two OracleTimeStamp values are not equal. Returns false otherwise.

Remarks

The following rules apply to the behavior of this method.

GetSysDate

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

Declaration

// C#
public static OracleTimeStamp GetSysDate();

Return Value

An OracleTimeStamp structure that represents the current date and time.

Parse

This static method gets an OracleTimeStamp structure and sets its value using the supplied string.

Declaration

// C#
public static OracleTimeStamp Parse(string datetime);

Parameters

Return Value

An OracleTimeStamp structure.

Exceptions

ArgumentException - The tsStr is an invalid string representation of an Oracle TIMESTAMP or the supplied tsStr is not in the timestamp format specified by the OracleGlobalization.TimeStampFormat property of the thread, which represents the Oracle NLS_TIMESTAMP_FORMAT parameter.

ArgumentNullException - The tsStr value 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()
  {
    // Set the nls_timestamp_format for the Parse() method
    OracleGlobalization info = OracleGlobalization.GetClientInfo();
    info.TimeStampFormat = "DD-MON-YYYY HH:MI:SS.FF AM";
    OracleGlobalization.SetThreadInfo(info);
    
    // construct OracleTimeStamp from a string using the format specified.
    OracleTimeStamp ts = 
      OracleTimeStamp.Parse("11-NOV-1999 11:02:33.444 AM");
      
    // Set the nls_timestamp_format for the ToString() method
    info.TimeStampFormat = "YYYY-MON-DD HH:MI:SS.FF AM";
    OracleGlobalization.SetThreadInfo(info);
 
    // Prints "1999-NOV-11 11:02:33.444000000 AM"
    Console.WriteLine(ts.ToString());    
  }
}

SetPrecision

This static method returns a new instance of an OracleTimeStamp with the specified fractional second precision.

Declaration

// C#
public static OracleTimeStamp SetPrecision(OracleTimeStamp value1,
    int fracSecPrecision);

Parameters

Return Value

An OracleTimeStamp structure with the specified fractional second precision.

Exceptions

ArgumentOutOfRangeException - fracSecPrecision is out of the specified range.

Remarks

The value specified in the supplied fracSecPrecision is used to perform a rounding off operation on the supplied OracleTimeStamp value. Depending on this value, 0 or more trailing zeros are displayed in the string returned by ToString().

Example

The OracleTimeStamp with a value of "December 31, 9999 23:59:59.99" results in the string "December 31, 9999 23:59:59.99000" when SetPrecision() is called with the fractional second precision set to 5.


OracleTimeStamp Static Operators

The OracleTimeStamp static operators are listed in Table 14-96.

Table 14-96 OracleTimeStamp Static Operators

Operator Description

operator +

Adds the supplied instance value to the supplied OracleTimeStamp and returns a new OracleTimeStamp structure (Overloaded)

operator ==

Determines if two OracleTimeStamp values are equal

operator >

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

operator >=

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

operator !=

Determines if the two OracleTimeStamp values are not equal

operator <

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

operator <=

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

operator -

Subtracts the supplied instance value from the supplied OracleTimeStamp and returns a new OracleTimeStamp structure (Overloaded)


operator +

operator+ adds the supplied object to the OracleTimeStamp and returns a new OracleTimeStamp structure.

Overload List:

operator + (OracleTimeStamp, OracleIntervalDS)

This static operator adds the supplied OracleIntervalDS to the OracleTimeStamp and returns a new OracleTimeStamp structure.

Declaration

// C#
public static operator + (OracleTimeStamp value1, OracleIntervalDS value2);

Parameters

Return Value

An OracleTimeStamp.

Remarks

If either parameter has a null value, the returned OracleTimeStamp has a null value.

operator + (OracleTimeStamp, OracleIntervalYM)

This static operator adds the supplied OracleIntervalYM to the supplied OracleTimeStamp and returns a new OracleTimeStamp structure.

Declaration

// C#
public static operator + (OracleTimeStamp value1, OracleIntervalYM value2);

Parameters

Return Value

An OracleTimeStamp.

Remarks

If either parameter has a null value, the returned OracleTimeStamp has a null value.

operator + (OracleTimeStamp, TimeSpan)

This static operator adds the supplied TimeSpan to the supplied OracleTimeStamp and returns a new OracleTimeStamp structure.

Declaration

// C#
public static operator + (OracleTimeStamp value1, TimeSpan value2);

Parameters

Return Value

An OracleTimeStamp.

Remarks

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

operator ==

This static operator determines if two OracleTimeStamp values are equal.

Declaration

// C#
public static bool operator == (OracleTimeStamp value1,
   OracleTimeStamp 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 static operator determines if the first of two OracleTimeStamp values is greater than the second.

Declaration

// C#
public static bool operator > (OracleTimeStamp value1, 
   OracleTimeStamp value2);

Parameters

Return Value

Returns true if the first OracleTimeStamp value is greater than the second; otherwise, returns false.

Remarks

The following rules apply to the behavior of this method.

operator >=

This static operator determines if the first of two OracleTimeStamp values is greater than or equal to the second.

Declaration

// C#
public static bool operator >= (OracleTimeStamp value1, 
  OracleTimeStamp value2);

Parameters

Return Value

Returns true if the first OracleTimeStamp is greater than or equal to the second; otherwise returns false.

Remarks

The following rules apply to the behavior of this method.

operator !=

This static operator determines if two OracleTimeStamp values are not equal.

Declaration

// C#
public static bool operator != (OracleTimeStamp value1, 
  OracleTimeStamp value2);

Parameters

Return Value

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

Remarks

The following rules apply to the behavior of this method.

operator <

This static operator determines if the first of two OracleTimeStamp values is less than the second.

Declaration

// C#
public static bool operator < (OracleTimeStamp value1, 
  OracleTimeStamp value2);

Parameters

Return Value

Returns true if the first OracleTimeStamp is less than the second; otherwise, returns false.

Remarks

The following rules apply to the behavior of this method.

operator <=

This static operator determines if the first of two OracleTimeStamp values is less than or equal to the second.

Declaration

// C#
public static bool operator <= (OracleTimeStamp value1, 
  OracleTimeStamp value2);

Parameters

Return Value

Returns true if the first OracleTimeStamp is less than or equal to the second; otherwise, returns false.

Remarks

The following rules apply to the behavior of this method.

operator -

operator- subtracts the supplied value, from the supplied OracleTimeStamp value, and returns a new OracleTimeStamp structure.

Overload List:

operator - (OracleTimeStamp, OracleIntervalDS)

This static operator subtracts the supplied OracleIntervalDS value, from the supplied OracleTimeStamp value, and return a new OracleTimeStamp structure.

Declaration

// C#
public static operator - (OracleTimeStamp value1, OracleIntervalDS value2);

Parameters

Return Value

An OracleTimeStamp structure.

Remarks

If either parameter has a null value, the returned OracleTimeStamp has a null value.

operator - (OracleTimeStamp, OracleIntervalYM)

This static operator subtracts the supplied OracleIntervalYM value, from the supplied OracleTimeStamp value, and returns a new OracleTimeStamp structure.

Declaration

// C#
public static operator - (OracleTimeStamp value1, OracleIntervalYM value2);

Parameters

Return Value

An OracleTimeStamp structure.

Remarks

If either parameter has a null value, the returned OracleTimeStamp has a null value.

operator - (OracleTimeStamp, TimeSpan)

This static operator subtracts the supplied TimeSpan value, from the supplied OracleTimeStamp value, and returns a new OracleTimeStamp structure.

Declaration

// C#
public static operator - (OracleTimeStamp value1, TimeSpan value2);

Parameters

Return Value

An OracleTimeStamp structure.

Remarks

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


OracleTimeStamp Static Type Conversions

The OracleTimeStamp static type conversions are listed in Table 14-97.

Table 14-97 OracleTimeStamp Static Type Conversions

Operator Description

explicit operator OracleTimeStamp

Converts an instance value to an OracleTimeStamp structure (Overloaded)

implicit operator OracleTimeStamp

Converts an instance value to an OracleTimeStamp structure (Overloaded)

explicit operator DateTime

Converts an OracleTimeStamp value to a DateTime structure


explicit operator OracleTimeStamp

explicit operator OracleTimeStamp converts the supplied value to an OracleTimeStamp structure

Overload List:

explicit operator OracleTimeStamp(OracleTimeStampLTZ)

This static type conversion operator converts an OracleTimeStampLTZ value to an OracleTimeStamp structure.

Declaration

// C#
public static explicit operator OracleTimeStamp(OracleTimeStampLTZ value1);

Parameters

Return Value

The returned OracleTimeStamp contains the date and time of the OracleTimeStampLTZ structure.

Remarks

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

explicit operator OracleTimeStamp(OracleTimeStampTZ)

This static type conversion operator converts an OracleTimeStampTZ value to an OracleTimeStamp structure.

Declaration

// C#
public static explicit operator OracleTimeStamp(OracleTimeStampTZ value1);

Parameters

Return Value

The returned OracleTimeStamp contains the date and time information from value1, but the time zone information from value1 is truncated.

Remarks

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

explicit operator OracleTimeStamp(string)

This static type conversion operator converts the supplied string to an OracleTimeStamp structure.

Declaration

// C#
public static explicit operator OracleTimeStamp(string tsStr);

Parameters

Return Value

An OracleTimeStamp.

Exceptions

ArgumentException - The tsStr is an invalid string representation of an Oracle TIMESTAMP or the tsStr is not in the timestamp format specified by the thread's OracleGlobalization.TimeStampFormat property, which represents the Oracle NLS_TIMESTAMP_FORMAT parameter.

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 OracleTimeStampSample
{
  static void Main()
  {
    // Set the nls_timestamp_format for the explicit
    // operator OracleTimeStamp(string)
    OracleGlobalization info = OracleGlobalization.GetClientInfo();
    info.TimeStampFormat = "DD-MON-YYYY HH:MI:SS.FF AM";
    OracleGlobalization.SetThreadInfo(info);
    
    // construct OracleTimeStamp from a string using the format specified.
    OracleTimeStamp ts = new OracleTimeStamp("11-NOV-1999 11:02:33.444 AM");
    
    // Set the nls_timestamp_format for the ToString method
    info.TimeStampFormat = "YYYY-MON-DD HH:MI:SS.FF AM";
    OracleGlobalization.SetThreadInfo(info);
 
    // Prints "1999-NOV-11 11:02:33.444000000 AM"   
    Console.WriteLine(ts.ToString());    
  }
}

implicit operator OracleTimeStamp

This static type conversion operator converts a value to an OracleTimeStamp structure.

Overload List:

implicit operator OracleTimeStamp(OracleDate)

This static type conversion operator converts an OracleDate value to an OracleTimeStamp structure.

Declaration

// C#
public static implicit operator OracleTimeStamp (OracleDate value1);

Parameters

Return Value

An OracleTimeStamp structure that contains the date and time of the OracleDate structure, value1.

Remarks

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

implicit operator OracleTimeStamp(DateTime)

This static type conversion operator converts a DateTime value to an OracleTimeStamp structure.

Declaration

// C#
public static implicit operator OracleTimeStamp(DateTime value);

Parameters

Return Value

An OracleTimeStamp structure.

explicit operator DateTime

This static type conversion operator converts an OracleTimeStamp value to a DateTime structure.

Declaration

// C#
public static explicit operator DateTime(OracleTimeStamp value1);

Parameters

Return Value

A DateTime containing the date and time in the current instance.

Exceptions

OracleNullValueException - The OracleTimeStamp structure has a null value.

Remarks

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


OracleTimeStamp Properties

The OracleTimeStamp properties are listed in Table 14-98.

Table 14-98 OracleTimeStamp Properties

Properties Description

BinData

Returns an array of bytes that represents an Oracle TIMESTAMP in Oracle internal format

Day

Specifies the day component of an OracleTimeStamp

IsNull

Indicates whether or not the OracleTimeStamp instance has a null value

Hour

Specifies the hour component of an OracleTimeStamp

Millisecond

Specifies the millisecond component of an OracleTimeStamp

Minute

Specifies the minute component of an OracleTimeStamp

Month

Specifies the month component of an OracleTimeStamp

Nanosecond

Specifies the nanosecond component of an OracleTimeStamp

Second

Specifies the second component of an OracleTimeStamp

Value

Specifies the date and time that is stored in the OracleTimeStamp structure

Year

Specifies the year component of an OracleTimeStamp


BinData

This property returns an array of bytes that represents an Oracle TIMESTAMP in Oracle internal format.

Declaration

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

Property Value

A byte array that represents an Oracle TIMESTAMP in an internal format.

Exceptions

OracleNullValueException - The current instance has a null value.

Day

This property specifies the day component of an OracleTimeStamp.

Declaration

// C#
public int Day{get;}

Property Value

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

Exceptions

OracleNullValueException - The current instance 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 specifies the hour component of an OracleTimeStamp.

Declaration

// C#
public int Hour{get;}

Property Value

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

Exceptions

OracleNullValueException - The current instance has a null value.

Millisecond

This property gets the millisecond component of an OracleTimeStamp.

Declaration

// C#
public double Millisecond{get;}

Property Value

A number that represents a millisecond. Range of Millisecond is (0 to 999.999999).

Exceptions

OracleNullValueException - The current instance has a null value.

Minute

This property gets the minute component of an OracleTimeStamp.

Declaration

// C#
public int Minute{get;}

Property Value

A number that represent a minute. Range of Minute is (0 to 59).

Exceptions

OracleNullValueException - The current instance has a null value.

Month

This property gets the month component of an OracleTimeStamp.

Declaration

// C#
public int Month{get;}

Property Value

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

Exceptions

OracleNullValueException - The current instance has a null value.

Nanosecond

This property gets the nanosecond component of an OracleTimeStamp.

Declaration

// C#
public int Nanosecond{get;}

Property Value

A number that represents a nanosecond. Range of Nanosecond is (0 to 999999999).

Exceptions

OracleNullValueException - The current instance has a null value.

Second

This property gets the second component of an OracleTimeStamp.

Declaration

// C#
public int Second{get;}

Property Value

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

Exceptions

OracleNullValueException - The current instance has a null value.

Value

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

Declaration

// C#
public DateTime Value{get;}

Property Value

A DateTime.

Exceptions

OracleNullValueException - The current instance has a null value.

Year

This property gets the year component of an OracleTimeStamp.

Declaration

// C#
public int Year{get;}

Property Value

A number that represents a year. The range of Year is (-4712 to 9999).

Exceptions

OracleNullValueException - The current instance has a null value.


OracleTimeStamp Methods

The OracleTimeStamp methods are listed in Table 14-99.

Table 14-99 OracleTimeStamp Methods

Methods Description

AddDays

Adds the supplied number of days to the current instance

AddHours

Adds the supplied number of hours to the current instance

AddMilliseconds

Adds the supplied number of milliseconds to the current instance

AddMinutes

Adds the supplied number of minutes to the current instance

AddMonths

Adds the supplied number of months to the current instance

AddNanoseconds

Adds the supplied number of nanoseconds to the current instance

AddSeconds

Adds the supplied number of seconds to the current instance

AddYears

Adds the supplied number of years to the current instance

CompareTo

Compares the current OracleTimeStamp 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 OracleTimeStamp instance (Overloaded)

GetHashCode

Returns a hash code for the OracleTimeStamp instance

GetDaysBetween

Subtracts an OracleTimeStamp value from the current instance and returns an OracleIntervalDS that represents the time difference between the supplied OracleTimeStamp and the current instance

GetYearsBetween

Subtracts value1 from the current instance and returns an OracleIntervalYM that represents the difference between value1 and the current instance using OracleIntervalYM

GetType

Inherited from System.Object

ToOracleDate

Converts the current OracleTimeStamp structure to an OracleDate structure

ToOracleTimeStampLTZ

Converts the current OracleTimeStamp structure to an OracleTimeStampLTZ structure

ToOracleTimeStampTZ

Converts the current OracleTimeStamp structure to an OracleTimeStampTZ structure

ToString

Converts the current OracleTimeStamp structure to a string


AddDays

This method adds the supplied number of days to the current instance.

Declaration

// C#
public OracleTimeStamp AddDays(double days);

Parameters

Return Value

An OracleTimeStamp.

Exceptions

ArgumentOutofRangeException - The argument value is out of the specified range.

OracleNullValueException - The current instance has a null value.

AddHours

This method adds the supplied number of hours to the current instance.

Declaration

// C#
public OracleTimeStamp AddHours(double hours);

Parameters

Return Value

An OracleTimeStamp.

Exceptions

ArgumentOutofRangeException - The argument value is out of the specified range.

OracleNullValueException - The current instance has a null value.

AddMilliseconds

This method adds the supplied number of milliseconds to the current instance.

Declaration

// C#
public OracleTimeStamp AddMilliseconds(double milliseconds);

Parameters

Return Value

An OracleTimeStamp.

Exceptions

ArgumentOutofRangeException - The argument value is out of the specified range.

OracleNullValueException - The current instance has a null value.

AddMinutes

This method adds the supplied number of minutes to the current instance.

Declaration

// C#
public OracleTimeStamp AddMinutes(double minutes);

Parameters

Return Value

An OracleTimeStamp.

Exceptions

ArgumentOutofRangeException - The argument value is out of the specified range.

OracleNullValueException - The current instance has a null value.

AddMonths

This method adds the supplied number of months to the current instance.

Declaration

// C#
public OracleTimeStamp AddMonths(long months);

Parameters

Return Value

An OracleTimeStamp.

Exceptions

ArgumentOutofRangeException - The argument value is out of the specified range.

OracleNullValueException - The current instance has a null value.

AddNanoseconds

This method adds the supplied number of nanoseconds to the current instance.

Declaration

// C#
public OracleTimeStamp AddNanoseconds(long nanoseconds);

Parameters

Return Value

An OracleTimeStamp.

Exceptions

OracleNullValueException - The current instance has a null value.

AddSeconds

This method adds the supplied number of seconds to the current instance.

Declaration

// C#
public OracleTimeStamp AddSeconds(double seconds);

Parameters

Return Value

An OracleTimeStamp.

Exceptions

ArgumentOutofRangeException - The argument value is out of the specified range.

OracleNullValueException - The current instance has a null value.

AddYears

This method adds the supplied number of years to the current instance.

Declaration

// C#
public OracleTimeStamp AddYears(int years);

Parameters

Return Value

An OracleTimeStamp.

Exceptions

ArgumentOutofRangeException - The argument value is out of the specified range.

OracleNullValueException - The current instance has a null value.

CompareTo

This method compares the current OracleTimeStamp 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 a number that is:

Less than zero: if the current OracleTimeStamp instance value is less than that of obj.

Zero: if the current OracleTimeStamp instance and obj values are equal.

Greater than zero: if the current OracleTimeStamp instance value is greater than that of obj.

Implements

IComparable

Exceptions

ArgumentException - The obj parameter is not of type OracleTimeStamp.

Remarks

The following rules apply to the behavior of this method.

Equals

Overrides Object

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

Declaration

// C#
public override bool Equals(object obj);

Parameters

Return Value

Returns true if the obj is of type OracleTimeStamp 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 OracleTimeStamp instance.

Declaration

// C#
public override int GetHashCode();

Return Value

A number that represents the hash code.

GetDaysBetween

This method subtracts an OracleTimeStamp value from the current instance and returns an OracleIntervalDS that represents the time difference between the supplied OracleTimeStamp structure and the current instance.

Declaration

// C#
public OracleIntervalDS GetDaysBetween(OracleTimeStamp value1);

Parameters

Return Value

An OracleIntervalDS that represents the interval between two OracleTimeStamp values.

Remarks

If either the current instance or the parameter has a null value, the returned OracleIntervalDS has a null value.

GetYearsBetween

This method subtracts an OracleTimeStamp value from the current instance and returns an OracleIntervalYM that represents the time difference between the OracleTimeStamp value and the current instance.

Declaration

// C#
public OracleIntervalYM GetYearsBetween(OracleTimeStamp value1);

Parameters

Return Value

An OracleIntervalYM that represents the interval between two OracleTimeStamp values.

Remarks

If either the current instance or the parameter has a null value, the returned OracleIntervalYM has a null value.

ToOracleDate

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

Declaration

// C#
public OracleDate ToOracleDate();

Return Value

The returned OracleDate contains the date and time in the current instance.

Remarks

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

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

ToOracleTimeStampLTZ

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

Declaration

// C#
public OracleTimeStampLTZ ToOracleTimeStampLTZ();

Return Value

The returned OracleTimeStampLTZ contains date and time in the current instance.

Remarks

If the value of the current instance has a null value, the value of the returned OracleTimeStampLTZ structure has a null value.

ToOracleTimeStampTZ

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

Declaration

// C#
public OracleTimeStampTZ ToOracleTimeStampTZ();

Return Value

The returned OracleTimeStampTZ contains the date and time from the OracleTimeStamp and the time zone from the OracleGlobalization.TimeZone of the thread.

Remarks

If the value of the current instance has a null value, the value of the returned OracleTimeStampTZ structure has a null value.

ToString

Overrides Object

This method converts the current OracleTimeStamp structure to a string.

Declaration

// C#
public override string ToString();

Return Value

A string that represents the same date and time as the current OracleTimeStamp structure.

Remarks

The returned value is a string representation of an OracleTimeStamp in the format specified by the OracleGlobalization.TimeStampFormat property of the thread.

The names and abbreviations used for months and days are in the language specified by the OracleGlobalization's DateLanguage and Calendar properties of the thread. 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 ToStringSample
{
  static void Main()
  {
    // Set the nls_timestamp_format for the OracleTimeStamp(string)
    // constructor
    OracleGlobalization info = OracleGlobalization.GetClientInfo();
    info.TimeStampFormat = "DD-MON-YYYY HH:MI:SS.FF AM";
    OracleGlobalization.SetThreadInfo(info);
    
    // construct OracleTimeStamp from a string using the format specified.
    OracleTimeStamp ts = new OracleTimeStamp("11-NOV-1999 11:02:33.444 AM");
    
    // Set the nls_timestamp_format for the ToString() method
    info.TimeStampFormat = "YYYY-MON-DD HH:MI:SS.FF AM";
    OracleGlobalization.SetThreadInfo(info);
 
    // Prints "1999-NOV-11 11:02:33.444000000 AM"      
    Console.WriteLine(ts.ToString());    
  }
}