Not getting date-time in specific format in PostgreSQL

Viewed 61

What I'm trying is

SELECT TO_CHAR(NOW(), 'YYYY-MM-DDTHH24:MI:SS.US');

Actual Output:

           to_char            
------------------------------
 2021-06-17THH24:05:19.815403


but my Expected output:

           to_char            
------------------------------
 2021-06-17T06:05:19.815403


here When I use T then hour print like HH24.

1 Answers

Try placing the T between double quotes:

SELECT to_char(now(), 'YYYY-MM-DD"T"HH24:MI:SS.US');
          to_char           
----------------------------
 2021-06-17T08:11:11.913287
Related