Send feedback on this topic.
Teradata.Client.Provider
Formatting and Parsing Strings
.NET Data Provider for Teradata > Developer's Guide > Data Types > Interval Data Types > Formatting and Parsing Strings

Each interval type will support the conversion to a string or parsing of a string to create an interval type. The conversions are not culture sensitive. Interval specific types support the G and L/l format specifiers.

Format Specifier Example Comments
"G"

TdIntervalHourToSecond

   4300:25:59.30

4300 hours, 25 minutes, 59 seconds and 300000 microseconds.

This is the default format specifier in any ToString method that contains a format specifier.

"L" or "l"

TdIntervalYearToMonth

Interval '39-01' Year To Month

39 years and 1 month.

The string representation of the interval will be in a format where the string can be used as a literal in a Teradata SQL statement.

Standard Format Specifiers

G Format Specifier -- ANSI string representation

When the G format specifier is used to convert an interval type to a string, the ANSI string representation of the type is returned. In this conversion all of the cultural information is ignored. Each of the types have the following ANSI representation:

Interval Type ANSI Representation Format Examples
TdIntervalYearToMonth

year(precision)-mm

   year -- years
   precision -- length (1-4)
   mm -- months (00-99)

9999-11

   9999 years
   11 months

TdIntervalYear

year(precision)

   year -- years
   precision -- length (1-4)

821

   821 years

TdIntervalMonth

month(precision)

   month -- months
   precision -- length (1-4)

1000

   1000 months

TdIntervalDayToSecond

day(precision) hh:mm:ss.f(fprecision)

   day -- days
   precision -- length(1-4)
   hh -- hours (00-23)
   mm -- minutes (00-59)
   ss -- seconds (00-59)
   f -- microseconds
    fprecision -- length(0-6)

23 22:30:45.007

   23 days
   22 hours
   30 minutes
   45 seconds
   7000 microseconds

TdIntervalDayToMinute

day(precision) hh:mm

   day -- days
   precision -- length(1-4)
   hh -- hours (00-23)
   mm -- minutes (00-59)

2654 22:30

   2654 days
   22 hours
   30 minutes

TdIntervalDayToHour

day(precision) hh

   day -- days
   precision -- length(1-4)
   hh -- hours (00-23)

101 23

   101 days
   23 hours

TdIntervalDay

day(precision)

   day -- days
   precision -- length(1-4)

23

   23 days

TdIntervalHourToSecond

hour(precision):mm:ss.f(fprecision)

   hour -- hours
   precision -- length(1-4)
   mm -- minutes (00-59)
   ss -- seconds (00-59)
   f -- microseconds
   fprecision -- length(0-6)

980:30:45.000721

   980 hours
   30 minutes
   45 seconds
   721 microseconds

TdIntervalHourToMinute

hour(precision):mm

   hour -- hours
   precision -- length(1-4)
   mm -- minutes (00-59)

22:30

   22 hours
   30 minuites

TdIntervalHour

hour(precision)

   hour -- hours
   precision -- length(1-4)

877

   877 hours

TdIntervalMinuteToSecond

minute(precision):ss.f(fprecision)

   minute -- minutes
   precision -- length(1-4)
   ss -- seconds (00-59)
   f -- microseconds
   fprecision -- length(0-6)

30:45.8721

   30 minutes
   45 seconds
   872100 microseconds

TdIntervalMinute

minute(precision)

   minute -- minutes
   precision -- length(1-4)

230

   230 minutes

TdIntervalSecond

second(precision).f(fprecision)

   second -- seconds
   precision -- length(1-4)
   f -- microseconds
   fprecision -- length(0-6)

215.90

   215 seconds
   900000 microseconds

The G format specifier is the default used when the following methods are invoked: ToString(), IConvertible.ToString(IFormatProvider provider). It is also the default specifier when the format parameter of ToString(String format) or IFormattable.ToString(String format, IFormatProvider provider) is null.

The ANSI string representation of an interval type can also be parsed and converted into an interval type by the Parse and TryParse methods.

L or l Format Specifier -- Teradata String Literal for Interval Types

The ToString methods for each of the interval types support the conversion of the type into a string that is equivalent to the Teradata Literal representation. The format specifier L or l is used to perform this conversion.

The Teradata Literal representation is similar to the ANSI representation, except that the interval is surrounded by apostrophes. Cultural information is also ignored in the conversion. Each of the interval types has the following literal representation:

Interval Type Literal Representation Format
TdIntervalYearToMonth

Interval '9999-01' Year To Month

   9999 -- number of years
   01 -- number of months (0-99)

TdIntervalYear

Interval '821' Year

   821 -- number of years

TdIntervalMonth

Interval '1000' Month

   1000 -- number of months

TdIntervalDayToSecond

Interval '12 22:30:45.007' Day To Second

   12 -- number of days
   22 -- number (00-23) associated with a hours
   30 -- number (00-59) associated with a minutes
   45 -- number (00-59) associated with a seconds
   7000 -- number of microseconds

TdIntervalDayToMinute

Interval '2643 22:30' Day To Minute

   2643 -- number of days
   22 -- number (00-23) associated with a hours
   30 -- number (00-59) associated with a minutes

TdIntervalDayToHour

Interval '101 23' Day To Hour

   101 -- number of days
   23 -- number (00-23) associated with a hours

TdIntervalDay

Interval '23' Day

   23 -- number of days

TdIntervalHourToSecond

Interval '980:30:45.000721' Hour To Second

   980 -- number of hours
   30 -- number (00-59) associated with a minutes
   45 -- number (00-59) associated with a seconds
   721 -- number of microseconds

TdIntervalHourToMinute

Interval '22:30' Hour To Minute

   22 -- number of hours
   30 -- number (00-59) associated with a minutes

TdIntervalHour

Interval '877' Hour

   877 -- number of hours

TdIntervalMinuteToSecond

Interval '30:45.8721' Minute To Second

   30 -- number of minutes
   45 -- number (00-59) associated with a seconds
   872100 -- number of microseconds

TdIntervalMinute

Interval '230' Minute

   230 -- number of minutes

TdIntervalSecond

Interval '215.90' Second

   215 -- number of seconds
   900000 -- number of microseconds

Parsing strings into Teradata TdIntervals (TdIntervalYearToMonth, TdIntervalYear, etc)

In order to convert a string to one of the interval types the Parse method must be called. The string must either be formatted as an ANSI interval or a Teradata literal. A A System.FormatException will be thrown by the provider when the format is invalid. Cultural information is not supported.

The following example shows how to call parse to convert a string that contains a interval into a TdIntervalYearToMonth object.

Parsing TdIntervalYearToMonth Example
Copy Code
    //The promotion period is 2 years and 6 months
    String promotionPeriod = "2-06"
    TdIntervalYearToMonth promotionInterval = TdIntervalYearToMonth.Parse(promotionPeriod);
    TdDate startDate = TdDate.Parse("2009-09-10");

    //Add the length of the promotion period to the start date
    TdDate endPromotion = startDate + promotionInterval;

    //Display the end of the promotion date - "2012-03-10"
    endPromotion.ToString();