SQL showing current timestamp in different formats Mysql

101 Views Asked by At

I need to show current UTC timestamp in a format '2021/05/10T18:30:36Z'

SELECT UTC_TIMESTAMP() FROM XYZ

gives me 2021-05-10 18:30:36

how do i add the / instead of - and use T and Z

1

There are 1 best solutions below

0
On BEST ANSWER
select DATE_FORMAT(UTC_TIMESTAMP(),'%Y/%m/%dT%TZ')

2021/05/10T18:51:07Z

Note that T doesn't really mean anything. And Z means UTC ZERO timezone, which is always the case with the UTC_TIMESTAMP function. Thus I have somewhat "hardcoded" those letters at the right place , and they are not real variables accepted by DATE_FORMAT()