Cons
Cons

Reputation: 1193

SQL / Add 2 zeros to String

I want to add 2 zero to the right of the next function: UNIX_TIMESTAMP (NOW()),

So instead of: 1369047810, I would get: 136904781000

I try this:

SELECT (UNIX_TIMESTAMP (NOW()) + RIGHT(REPLICATE('0', 2))))

but it doesn't help.

Upvotes: 0

Views: 132

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1269663

If you want it as a string, then you want to convert it to a string and then add the zeros. Something like:

SELECT (cast(UNIX_TIMESTAMP (NOW()) as varchar(255) + RIGHT(REPLICATE('0', 2))))

I think the string conversion is safer than doing arithmetic, if you want a string in the end. Multiplying values might cause arithmetic overflow.

Also, I associate the syntax UNIX_TIMESTAMP (NOW()) with MySQL (as I write this, there is no database tag on the question). The right syntax in that database would be:

select concat(cast(UNIX_TIMESTAMP (NOW()) as varchar(255), '00')

Upvotes: 1

juergen d
juergen d

Reputation: 204756

SELECT UNIX_TIMESTAMP (NOW()) * 100

Upvotes: 1

Related Questions