Miguel Mas Miguel Mas - 8 days ago 7
SQL Question

T-SQL CURRENT_TIMESTAMP behaviour

I have:

select convert(int, CURRENT_TIMESTAMP, 121) AS shipmentCode


With this I pretend to give a unique code to a shipment of products that also has some information in it (meaning that I can convert the code back to time and have the shipment's full date/hour)

But I expect the int in shipmentCode to change every time I execute the procedure and it does not.

But if I do:

select convert(varchar(255), CURRENT_TIMESTAMP, 121) AS shipmentCode


The varchar changes with the time. As I need the code to be a number:

Can someone please, explain why this happens?

Any alternatives to achieve what I need?

Answer

Try This : SELECT DATEDIFF(SECOND,'1990-1-1',GETDATE())

Comments