Varchar to timestamp with AM/PM

Database
Enthusiast

Varchar to timestamp with AM/PM

Hi All,

 

I have a value like '11/04/2017 09:25:39'  in char(19) . .i need to cast it to timestamp with AM/PM.pls help

1 REPLY
Teradata Employee

Re: Varchar to timestamp with AM/PM

If month/day/hour are always 2 digits then you can CAST to internal format for storage:

CAST('11/04/2017 09:25:39' AS TIMESTAMP(0) FORMAT 'mm/dd/yyyybhh:mi:ss')

 

Then if you want to display as a string with AM/PM, you can either set the default column format or apply explicit format, then CAST back to a string:

CAST(CAST(myTimestamp AS FORMAT 'mm/dd/yyyybhh:mi:ssbt') AS CHAR(22))