How to Convert DateTime To TimeStamp?

Using CAST(DateTime AS TIMESTAMP).

Below query shows how you can convert datetime to timestamp.

[sql]
DECLARE @DateTimeVariable DATETIME

SELECT @DateTimeVariable = GETDATE()

SELECT @DateTimeVariable AS DateTimeValue,
CAST(@DateTimeVariable AS TIMESTAMP) AS DateTimeConvertedToTimestampCAST

–Alternate Approach
SELECT @DateTimeVariable AS DateTimeValue,
CONVERT(TIMESTAMP, @DateTimeVariable ) AS DateTimeConvertedToTimestampCONVERT
[/sql]

Leave a Reply

Your email address will not be published. Required fields are marked *