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



Teradata.Client.Provider Namespace : TdTimestampWithTimeZone Structure
TdTimeStampWithTimeZone is a .Net Data Provider for Teradata specific type that represents a timestamp with a Time Zone and based on the Gregorian Calendar.
Object Model
TdTimestampWithTimeZone StructureTdTimestampWithTimeZone StructureTdTimestampWithTimeZone StructureTdTimestampWithTimeZone StructureTdTimestampWithTimeZone StructureTdTimestampWithTimeZone StructureTdTimestampWithTimeZone Structure
Syntax
Remarks

The .Net Framework 2.0 system type DateTime directly corresponds to the Teradata type Timestamp. The Framework does not contain a system type that corresponds to the Teradata type Timestamp With Time Zone. DateTime is only capable of specifying "time" as local time, UTC time, or an unspecified time. It does not support a Univeral Coordinated Time (UTC) offset. In order to solve this problem, the provider specific type TdTimestampWithTimeZone is used.

TdTimestampWithTimeZone allows a UTC Offset to be specified with a timestamp. A valid UTC Offset will be within the range of -12:59 to 13:00.

The UTC offset can be specified when invoking the constructor, or in the string that is to be parsed. For more information on UTC offset refer to the Teradata Manual, Sql Reference: DataTypes and Literals.

Similar to the SQL Timestamp With Time Zone data type, the TdTimestampWithTimeZone also support a scale for the sub-seconds --this is specified as a TdTimestampWithTimeZone.Microsecond. The scale can range from 0 to 6. The Microsecond and Scale are specified in the constructor. An example of a timestamp with a time zone is "2007-08-30 13:21:10.003214-08:00". This timestamp has a UTC offset of "-08:00", Microsecond of "003214", and a Scale of "6".

When a TdTimestampWithTimeZone is parsed (see TdTimestampWithTimeZone.Parse) the scale of the resulting TdTimestampWithTimeZone will be set to the actual scale of the fractional part of the TdTimestampWithTimeZone.

When data of a column that is a Timestamp With Time Zone is retrieved as a TdTimestampWithTimeZone (TdDataReader.GetTdTimestampWithTimeZone), it's scale will be set to the scale of the column.

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

A TdTimestampWithTimeZone 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 TdTimestampWithTimeZone is returned to an application using the TdParameter.ProviderSpecificValue property. The object that is returned from the TdParameter.Value property remains a System.String.

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

The TdTimestampWithTimeZone is daylight savings time agnostic.

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 WITH TIME ZONE)

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.Varchar, 0,
        System.Data.ParameterDirection.Output, true, 0, 0, null,    
        System.Data.DataRowVersion.Default, null);
            
   cmd.ExecuteNonQuery();
            
   // Using TdTimestampWithTimeZone to get the time that the student enrolled 
   // in the class
   TdTimestampWithTimeZone timeEnrolled = (TdTimestampWithTimeZone)cmd.Parameters[0].ProviderSpecificValue;
             
   // Add 5 days to the time Enrolled.
   TdTimestampwithTimeZone newTime = timeEnrolled + new TimeSpan(5, 0, 0);
             
   // Typecast the newTime to a TdDate
   TdDate dateEnrolled = (TdDate)timeEnrolled;
             
   // Print out the timeEnrolled to the console
   Console.WriteLine("Time enrolled {0}", timeEnrolled);
             
   // Convert the timeEnrolled to a String
   String enrolled = timeEnrolled.ToString();
}
Inheritance Hierarchy

System.Object
   System.ValueType
      Teradata.Client.Provider.TdTimestampWithTimeZone

Requirements

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

See Also

Reference

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