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



Teradata.Client.Provider Namespace : TdTimestamp Structure
TdTimestamp is a .Net Data Provider for Teradata specific type that represents a timestamp that is based on the Gregorian Calendar.
Object Model
TdTimestamp StructureTdTimestamp StructureTdTimestamp StructureTdTimestamp StructureTdTimestamp StructureTdTimestamp Structure
Syntax
Remarks

The .Net Framework system type directly corresponds to the Teradata type Timestamp. Therefore, the .Net Data Provider for Teradata Version 1.2 and earlier versions map Timestamp to System.DateTime.

The Provider Specific Types for Date And Time that are supported in the release of version 12.0 of the provider makes available custom types that directly correspond to Teradata Date And Time Types. Although System.DateTime maps directly to Teradata Timestamp, a provider specific type will be provided to applications that will also map to Timestamp called TdTimestamp.

The main difference between TdTimestamp and System.DateTime is that TdTimestamp contains a scale that is associated with the sub-second component of the timestamp. This directly corresponds with the Teradata Timestamp data type.

TdTimestamp also supports TdTimestamp.Null. This is a very important feature. An application is no longer required to call TdDataReader.IsDBNull before invoking the corresponding TdDataReader "Get" method. This will improve overall performance.

The TdTimestamp.Scale can range from 0 to 6. This is similar to Teradata Database's Timestamp type. The sub-seconds is specified as a TdTimestamp.Microsecond. The Microsecond and Scale are specified in the constructor. An example of a timestamp is "2001-12-10 15:31:11.0021". This timestamp has a Microsecond of "2100", and a Scale of "4".

When a TdTimestamp is parsed (see TdTimestamp.Parse) the scale of the resulting TdTimestamp will be set to the actual scale of the fractional component of the timestamp.

When data of a column that is a Timestamp is retrieved as a TdTimestamp, it's scale will be set to the scale of the column.

The TdTimestamp structure allows arithmetic, comparison, and conversion operations to be performed.

A TdTimestamp value can also be specified as an In, Out, or InOut parameter to a Stored Procedure. In order to maintain backward compatibility with previous versions of the provider --versions earlier than 12.0--, the Connection String Attribute Enable TdDateTime must be set to false. When this is done, a TdTimestamp is returned to an application using the TdParameter.ProviderSpecificValue property. The object that is returned from the TdParameter.Value property remains a System.DateTime.

If the attribute Enable TdDateTime is set to true a TdTimestamp is returned to the application through the TdParameter.Value.

Example

The following example calls a stored procedure that returns a timestamp as an output parameter. The procedure that is called has the signature

TimeEnrolledInClass(IN studentId VARCHAR(9), IN classId VARCHAR(9), OUT timeEnrolled TIMESTAMP)

Public void TimeExample(TdCommand cmd, String studentId, String classId)
{
   cmd.Parameters.Clear();
  
   cmd.CommandText = "TimeEnrolledInClass";
   cmd.CommandType = CommandType.StoredProcedure;
            
   cmd.Parameters.Add(null, TdType.Varchar, 9,
        System.Data.ParameterDirection.Input, true, 0, 0, null,    
        System.Data.DataRowVersion.Default, studentId);
            
   cmd.Parameters.Add(null, TdType.Varchar, 9,
        System.Data.ParameterDirection.Input, true, 0, 0, null,    
        System.Data.DataRowVersion.Default, classId);
            
   cmd.Parameters.Add(null, TdType.Timestamp, 0,
        System.Data.ParameterDirection.Output, true, 0, 0, null,    
        System.Data.DataRowVersion.Default, null);
            
   cmd.ExecuteNonQuery();
            
   // Using TdTimestam to get the time that the student enrolled 
   // in the class
   TdTimestamp timeEnrolled = (TdTimestamp)cmd.Parameters[2].ProviderSpecificValue;
             
   // Going to add 5 days to the time Enrolled.
   TdTimestamp newTime = timeEnrolled + new TimeSpan(5, 0, 0);
             
   // going to typecast the newTime to a TdDate
   TdDate dateEnrolled = (TdDate)timeEnrolled;
             
   // going to print out the timeEnrolled to the console
   Console.WriteLine("Time enrolled {0}", timeEnrolled);
             
   // going to convert the timeEnrolled to a String
   String enrolled = timeEnrolled.ToString();
}
Inheritance Hierarchy

System.Object
   System.ValueType
      Teradata.Client.Provider.TdTimestamp

Requirements

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

See Also

Reference

TdTimestamp Members
Teradata.Client.Provider Namespace
Date And Time Connection String Attribute
Enabling Provider Specific Types
Provider Specific Type: Date And Time Overview