Formatting CURRENT_TIMESTAMP

Database
Enthusiast

Formatting CURRENT_TIMESTAMP

Hi All,

I want to select the current_timestamp in a specific format 'YYYYMMDDHH24MISS'.

Can you please let me know how I should go about it?

7 REPLIES
Enthusiast

Re: Formatting CURRENT_TIMESTAMP

select CAST((current_timestamp(0) (format 'YYYYMMDDHHMISS')) AS VARCHAR(14))
Khurram
Enthusiast

Re: Formatting CURRENT_TIMESTAMP

If you are particular about current_timestamp, you can think of :

select cast((current_timestamp(FORMAT 'YYYYMMDD')) as char(8))||cast((current_timestamp(FORMAT 'HHMISS')) as char(6))

Enthusiast

Re: Formatting CURRENT_TIMESTAMP

Thanks Khurram and Raja. It helped :)

Teradata Employee

Re: Formatting CURRENT_TIMESTAMP

You dont need to cast to varchar/char if you are connected via CLI .... it is required on ODBC connectivity.

Enthusiast

Re: Formatting CURRENT_TIMESTAMP

Adeel,

I have a question, do we need to cast it to varchar while inserting through ODBC ? Or it is only required for display purpose?

Khurram
Teradata Employee

Re: Formatting CURRENT_TIMESTAMP

Its only for display purpose. You can insert it like '2014-01-01 00:00:00' just fine .... and this is the default format that is suggested to be used with TD.

Enthusiast

Re: Formatting CURRENT_TIMESTAMP

how to find different timezone from one time zone?