Time conversion—%TOTIME
Use this function when you want CDC Replication to convert a character, numeric, or time data type to a time data type during replication.
Syntax
%TOTIME(time)Parameters
- time
- Specifies a column or literal that can have one of the following
types:
- Time, in the format HMMSS or HHMMSS. For example, 71500 represents 7:15 AM and 223000 represents 10:30 PM.
- Numeric. This value must be positive, and if it contains a fractional part, the fraction must be zero.
- Character, in one of the following formats:
This format lets you specify a time value that contains six consecutive digits. Any number of blank characters can precede or follow the six digits. For example,[whitespace] digit digit digit digit digit digit [whitespace]%TOTIME ( 012537 )returns 01:25:37.
This format lets you specify a time value that contains valid separator characters (colon, comma, period or one or more spaces) between hours, minutes, and seconds. Any number of blank characters can precede the first digit or follow the last digit.[whitespace] digit [digit] separator digit [digit] [separator digit [digit]] [whitespace]You cannot specify more than one separator character in the time value. For example, %TOTIME (12:05.20) is not valid. You can omit the number of seconds, in which case the %TOTIME function assumes zero seconds. For example,
%TOTIME (returns 12:05:00. You can omit leading zeros in the number of hours, minutes, and seconds. For example,12:05
)%TOTIME (returns 12:05:20.12 5 20
)
This format lets you specify a time value that indicates AM or PM. You can specify AM and PM in a number of different ways, such as A, AM, Am, a, aM, am, P, or PM. Any number of blank characters can precede the first digit or follow the AM/PM specification.[whitespace] digit [digit] separator digit [digit] [whitespace] {A | a | P | p} [{M | m}] [whitespace]You cannot specify more than one separator character in the time value. For example,
%TOTIME (is not valid. You cannot specify seconds in this format. If you do so, the %TOTIME function assumes zero seconds. You can omit leading zeros in the number of hours and minutes. For example,04: 20 PM
)%TOTIME (returns 15:05:00.3 5 P
)
Result data type
This function returns a Time.
Examples
The following examples show the colon (:) as the separator character in the returned ISO (International Organization for Standardization) time values. Depending on your environment, a different character may separate the hours, minutes, and seconds in the output time.
| Input value (time) | Result |
|---|---|
012537 |
01:25:37 |
22:4:12 |
22:04:12 |
4:05P |
16:05:00 |
2 5 Am |
02:05:00 |
| 204521 | 20:45:21 |
| 91035.0000 | 09:10:35 |
| 250521 | 00:00:00 |
10: 10:35 |
00:00:00 |