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" |
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" |
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. |
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 |
9999-11 9999 years |
TdIntervalYear |
year(precision) year -- years |
821 821 years |
TdIntervalMonth |
month(precision) month -- months |
1000 1000 months |
TdIntervalDayToSecond |
day(precision) hh:mm:ss.f(fprecision) day -- days |
23 22:30:45.007 23 days |
TdIntervalDayToMinute |
day(precision) hh:mm day -- days |
2654 22:30 2654 days |
TdIntervalDayToHour |
day(precision) hh day -- days |
101 23 101 days |
TdIntervalDay |
day(precision) day -- days |
23 23 days |
TdIntervalHourToSecond |
hour(precision):mm:ss.f(fprecision) hour -- hours |
980:30:45.000721 980 hours |
TdIntervalHourToMinute |
hour(precision):mm hour -- hours |
22:30 22 hours |
TdIntervalHour |
hour(precision) hour -- hours |
877 877 hours |
TdIntervalMinuteToSecond |
minute(precision):ss.f(fprecision) minute -- minutes |
30:45.8721 30 minutes |
TdIntervalMinute |
minute(precision) minute -- minutes |
230 230 minutes |
TdIntervalSecond |
second(precision).f(fprecision) second -- seconds |
215.90 215 seconds |
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.
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 |
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 |
TdIntervalDayToMinute |
Interval '2643 22:30' Day To Minute 2643 -- number of days |
TdIntervalDayToHour |
Interval '101 23' Day To Hour 101 -- number of days |
TdIntervalDay |
Interval '23' Day 23 -- number of days |
TdIntervalHourToSecond |
Interval '980:30:45.000721' Hour To Second 980 -- number of hours |
TdIntervalHourToMinute |
Interval '22:30' Hour To Minute 22 -- number of hours |
TdIntervalHour |
Interval '877' Hour 877 -- number of hours |
TdIntervalMinuteToSecond |
Interval '30:45.8721' Minute To Second 30 -- number of minutes |
TdIntervalMinute |
Interval '230' Minute 230 -- number of minutes |
TdIntervalSecond |
Interval '215.90' Second 215 -- number of seconds |
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 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(); |