Send feedback on this topic.
Teradata.Client.Provider
Culture Specific Formatting and Parsing of Strings
.NET Data Provider for Teradata > Developer's Guide > Data Types > Date And Time Data Types > Culture Specific Formatting and Parsing of Strings

Each Date And Time type will support the conversion to a string or parsing a string to create a Date And Time type. The conversions will be culture sensitive.

Culture Specific Formatting

When the data of a Date And Time type is converting to a string or being created by parsing a string, the format to create or read a string representation of the date or time is retrieved from the System.Globalization.DateTimeFormatInfo object. This object is obtained from the System.Globalization.CultureInfo object that is used to provide culture specific information.

The format of a string representation is specified using a Format Specifier. A specifier is used when converting a Date And Time type into a string by calling the ToString method. A specifier can also be specified when calling Parse to create a Date And Time type from a string. The specifier describes the format of the data in the string.

Culture Specific Formatting with UTC Offset

In .Net Framework 2.0 there is no cultural or formatting information associated with the UTC offset. The Date And Time types that support a Time Zone will represent the Time Zone in a string in the following format:

    <sign>hh:mm,
      where
            sign indicates whether the offset is added or subtracted from the corresponding UTC time
            h is the hour
            m is the minute

The UTC offset will always appear after the time component.

Standard Format Specifiers

G Format Specifier -- ANSI string representation

When the G format specifier is used to convert a Date And Time type to a string, the ANSI string representation of the type is returned. In this conversion all of the cultural information contained in DateTimeFormatInfo is ignored. Each of the types have the following ANSI representation:

ANSI Representation Format Examples Date And Time Type

yyyy-MM-dd

MM -- number (1-12) associated with month

2001-12-10 TdDate

HH:mm:ss.ffffff

ffffff -- number of digits as specified by the Scale property

12:31:21.998212
01:09:11
21:54:01.0002
TdTime

HH:mm:ss.ffffffZ

HH -- 24 hour time
Z -- UTC Offset in the format hh:mm

02:43:12.0001-08:00
11:56:21+05:00
18:07:02.00230-10:00
TdTimeWithTimeZone
yyyy-MM-dd HH:mm:ss.ffffff 2010-12-15 22:10:03.0021
2009-01-21 01:32:09
TdTimestamp
yyyy-MM-dd HH:mm:ss.ffffffZ 2008-10-31 23:53:49.00201+09:30
2011-06-17 11:00:00-02:00
TdTimestampWithTimeZone

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

The ANSI string representation of a Date And Time type can also be parsed and converted into a Date And Time type by the Parse and TryParse methods.

L or l Format Specifier -- Teradata String Literal for Date And Time Types

The ToString methods for each of the Date And Time 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 date or time is surrounded by apostrophes. Cultural information is also ignored in the conversion. For example, the following are Teradata literal representations of a TdDate and TdTimestampWithTimeZone: Date '2001-10-04', Timestamp '2005-01-20 14:32:00.212+09:00'

Supported Format Specifiers

The following is a list of format specifiers that are supported for each provider specific Date And Time Types:

Specifier Name Example Supported by Provider Type
d Short date pattern 1/21/2010 TdDate
TdTimestamp
TdTimeStampWithTimeZone
D Long date pattern Friday, August 31, 2007 TdDate
TdTimestamp
TdTimestampWithTimeZone
f Full date/time pattern (short time) Friday, August 31, 2007 1:43 AM TdTimestamp
TdTimestampWithTimeZone
F Full date/time pattern (long time) Friday, August 31, 2007 1:43:12 AM TdTimestamp
TdTimestampWithTimeZone
g General date/time pattern (short time) 8/31/2007 1:43 AM TdTimestamp
TdTimestampWithTimeZone
G ANSI formatted Date/Time 2007-08-31 1:43:11
2008-11-02 02:07:03.33+02:00
TdDate
TdTime
TdTimeWithTimeZone
TdTimestamp
TdTimestampWithTimeZone
H General date/time pattern (long time) 8/31/2007 1:43:09 AM TdTimestamp
TdTimestampWithTimeZone
M or m Month day pattern December 25 TdDate
TdTimestamp
TdTimestampWithTimeZone
L or l Teradata string literal representation '2008-03-01'
'2007-10-15 12:30:21.2232'
'02:45:12.0021-08:00'
TdDate
TdTime
TdTimeWithTimeZone
TdTimestamp
TdTimestampWithTimeZone
o Round-trip date/time pattern 2007-08-31T13:43:11.0001
2008-02-01T02:56:32.999999-07:00
TdTimestamp
TdTimestampWithTimeZone
R or r RFC1123 Wed, 02 Mar 2008 01:01:01 GMT TdTimestamp
TdTimestampWithTimeZone
S Sortable date/time pattern 2010-01-31T09:34:31 TdTimestamp
t Short time pattern 2:05 AM TdTime
TdTimeWithTimeZone
TdTimestamp
TdTimestampWithTimeZone
T Long time pattern 2:05:01 AM TdTime
TdTimeWithTimeZone
TdTimestamp
TdTimestampWithTimeZone
u Universal sortable date/time pattern 2008-02-29 12:43:01.000001Z TdTimestamp
TdTimestampWithTimeZone
U Universal date/time pattern Saturday, February 02, 2008 9:01:01 AM TdTimestamp
Y or y Year month pattern February, 2008 TdDate
TdTimestamp
TdTimestampWithTimeZone

The following is an example of using the culture information and format specifiers to create a string representation of the Date And Time Types:

Date and Time Format Specifier Example
Copy Code
    TdTimeWithTimeZone ts = new TdTimeWithTimeZone(12, 43, 45, new TimeSpan(-8, 0));
    // The string will have the time as 12:43:45 PM
    String tmp1 = ts.ToString(“T”)

    // Going to change the Time separator. The object that is created will be
    // culture independent.
    DateTimeFormatInfo format = new DateTimeFormatInfo();
    format.TimeSeparator = “^”;

    // The string will have the time as 12^43^45 PM
    String tmp2 = ts.ToString(“T”, format);

Parsing strings into TdDate, TdTime, and TdTimestamp

In order to convert a string to one of the Date And Time types the Parse method must be called. The format that is specified is based upon information in the current System.Globalization.DateTimeFormatInfo object. If the format is invalid, a FormatException will be thrown by the provider.

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

Timestamp Conversion Example
Copy Code
    String vacationStart = "2007-06-10 06:00:00"
    TdTimestamp ts = TdTimestamp.Parse(vacationStart);
    TdDate newDate = christmas + daysToAdd;

    //The date component will be ignored
    TdTime tt = TdTime.Parse(vacationStart);

    //The time component will be ignored
    TdDate td = TdDate.Parse(vacationStart);

Parsing Strings that Contain a UTC Offset

The UTC offset must appear at the end of the string. For example,

UTC Example
Copy Code
    String vacationStart = "2007-06-10 06:00:00-08:00"
    TdTimestampWithTimeZone ts = TdTimestampWithTimeZone.Parse(vacationStart);