tymspy
tymspy

Reputation: 4270

How do we convert time in unix timestamp to string with radix 32 in MySQL

I want to convert the current time in unix timestamp to a string with radix 32 in MySQL

It can be achieved in JavaScript with the code below

'm' + prefix + Date.now().toString(32) + suffix

Sample SQL to give the idea (working incorrectly )

SET prefix = 'order'
SET suffix = 19;
SELECT 'm' + prefix + CONV( UNIX_TIMESTAMP(NOW()), 10, 32 ) + suffix AS   result

Upvotes: 1

Views: 263

Answers (1)

1000111
1000111

Reputation: 13519

+ is considered an arithmetic operator in MySQL.

You need to use CONCAT function to concatenate multiple strings like below:

SELECT CONCAT('m' , prefix , CONV( UNIX_TIMESTAMP(), 10, 32 ) , suffix) AS   result

Note: UNIX_TIMESTAMP() and UNIX_TIMESTAMP(NOW()) would return same value.

TEST:

SET @prefix := 'PRE';
SET @suffix := 'SUF';

SELECT CONCAT('m' , @prefix , CONV( UNIX_TIMESTAMP(), 10, 32 ) , @suffix) AS   result

Output: mPRE1BSVENHSUF

See Live Demo

Upvotes: 1

Related Questions