Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get DateTime value from timestamp type column?

I need a select from table which does not have column that tells when row was inserted, only timestamp column (values like: 0x0000000000530278). Some data was imported to the table yesterday and now I need to find out what exactly was imported :(

Is there a way to do it using only timestamp info? Here I found that:

  • Timestamp is a 8 bytes sequential Hex number, that has nothing to do with neither the date nor the time.
  • To get the current value of timestamp, use: @@DBTS.

Perhaps there is a way to find what was timestamp value around specific time? That would help to form a select. Or maybe there is a well known solution?

like image 513
Dandikas Avatar asked Oct 07 '08 11:10

Dandikas


People also ask

How do I get just the date from a TIMESTAMP?

You can use date(t_stamp) to get only the date part from a timestamp. Extracts the date part of the date or datetime expression expr.

Can we extract date from TIMESTAMP in SQL?

In MySQL, use the DATE() function to retrieve the date from a datetime or timestamp value. This function takes only one argument – either an expression which returns a date/datetime/ timestamp value or the name of a timestamp/datetime column. (In our example, we use a column of the timestamp data type.)

Is datetime and TIMESTAMP the same data type?

Just as DATETIME , the TIMESTAMP data type contains both the date and the time in the following format YYYY-MM-DD hh:mm:ss . However, unlike DATETIME , the TIMESTAMP data type has a fixed range between 1970-01-01 00:00:01 UTC to 2038-01-19 03:14:07 UTC.


2 Answers

The Transact-SQL timestamp data type is a binary data type with no time-related values.

So to answer your question: Is there a way to get DateTime value from timestamp type column?

The answer is: No

like image 84
kristof Avatar answered Sep 28 '22 07:09

kristof


The timestamp datatype in SQL Server 2005 is a synonym of rowversion and is just a number that is automatically incremented with each row update.

You can cast it to bigint to see its value.

To get what you want for new or updated rows, you should propably add another datetime column (lastupdate) and a trigger to update that column with each update.

For rows that have already been inserted in the past I don't think that you can do something to find the exact time.

like image 41
Panagiotis Korros Avatar answered Sep 28 '22 06:09

Panagiotis Korros