Send feedback on this topic.
Teradata.Client.Provider
TdPeriodTime Structure
Members  Example 



Teradata.Client.Provider Namespace : TdPeriodTime Structure
TdPeriodTime is a .Net Data Provider for Teradata specific type that represents a duration of time that is bound by beginning and ending times.
Object Model
TdPeriodTime StructureTdPeriodTime StructureTdTime StructureTdTime StructureTdPeriodTime StructureTdIntervalDayToSecond StructureTdTime StructureTdPeriodTime StructureTdPeriodTime StructureTdPeriodTime StructureTdPeriodTime StructureTdPeriodTime Structure
Syntax
Remarks

The Advanced SQL Engine introduced the Period type in release 13.00.00.00. Unfortunately, .NET does not contain a system type that corresponds to the Teradata Period(Time) type. Therefore, the Teradata provider exposes the TdPeriodTime type which enables an application to work with data of type Period(Time).

Similar to TdTime, TdPeriodTime supports a scale for the sub-seconds. The scale ranges from 0 to 6 and must be the same for both the beginning and ending bounds.

A period is an anchored duration. It represents a set of contiguous time granules within that duration. In the case of TdPeriodTime, the granularity of the time can range from 10^-6 (.000006 second) to 10^0 (1 second). The representation of a period is both inclusive and exclusive. It is inclusive in that the duration of the period begins from the beginning bound up to, but not including (excluding), the ending bound. For example suppose a TdPeriodTime contains the period of:

    "(13:12:21.05, 20:43:27.98)"

The period will include "13:12:21.05" and not "20:43:27.98". It has a duration of 07:31:06.93 (7 hours, 31 minutes, 6 seconds, 980000 microseconds). The time element "15:21:43" is also contained in the period.

The components of a period consists of the following:

A TdPeriodTime can also be specified as an In, Out, or InOut parameter to a Stored Procedure. The data will be returned to an application using either the TdParameter.ProviderSpecificValue or TdParameter.Value property. Retrieving the parameter using TdParameter.ProviderSpecificValue, will return the data using the Period structure. When TdParameter.Value is used, the data is returned as a String (this is the corresponding .Net type).

Example
The following is an example on retrieving a TdPeriodTime, modify the period, and then updating the period.
Public void PeriodDateExample(TdCommand cmd, String studentId)
{
   cmd.Parameter.Clear();
            
   cmd.CommandText = "SELECT timePeriod  " +
                   "FROM ClassDetention " +
                   "WHERE StudentId = ?";
            
   cmd.CommandType = CommandType.Text;
            
   // creating the parameter
   cmd.Parameters.Add(null, TdType.Varchar, 9,
      System.Data.ParameterDirection.Input, true, 0, 0, null,    
      System.Data.DataRowVersion.Default, studentId);
            
   TdDataReader dr = null;
 
   Int32 i = 0;
            
   TdPeriodTime detention;
            
   Try
   {
      dr = cmd.ExecuteReader();
            
      If (false == dr.Read())
      {
	       return;
      }
   
      // Retrieving the Period
      detention = dr.GetTdPeriodTime(0);
   }
   finally
   {
      if (dr != null)
      {
         dr.Close();
      }
   }
            
   // An additional 1 hour will be added to ending bound.
            
   // Specifying a TimeSpan of 1 hour
   System.TimeSpan extraHours = new TimeSpan(1, 0, 0);
            
   // Getting the ending bound of the period and
   // adding 1 hour to it
   detention = new TdPeriodTime(detention.Begin, detention.End + extraHours);    
            
   cmd.Parameters.Clear();
            
   cmd.CommandText = "UPDATE classDetention " +
                        "SET timePeriod = ? " +
                        "WHERE StudentId = ?";
            
   cmd.Parameters.Add(null, TdType.PeriodTime, 0,
         System.Data.ParameterDirection.Input, true, 0, 0, null,    
         System.Data.DataRowVersion.Default, detention);
            
   cmd.Parameters.Add(null, TdType.Varchar, 9,
         System.Data.ParameterDirection.Input, true, 0, 0, null,    
         System.Data.DataRowVersion.Default, studentId);
            
   cmd.ExecuteNonQuery();
}
Inheritance Hierarchy

System.Object
   System.ValueType
      Teradata.Client.Provider.TdPeriodTime

Requirements

Target Platforms: Windows 8.1, Windows 10, Windows Server 2012 R2, Windows Server 2016, Windows Server 2019

See Also

Reference

TdPeriodTime Members
Teradata.Client.Provider Namespace
TdTime Structure
Provider Specific Types: Period Type Overview