TimeStamp Conversion From HexaDecimal - sql-server

How can I convert a hexadecimal timestamp to date time in SQL server.
I tried Cast/Convert but it throws error.
Regards,
Rahul

You can't. "The Transact-SQL timestamp data type is different from the timestamp data type defined in the SQL-2003 standard. The SQL-2003 timestamp data type is equivalent to the Transact-SQL datetime data type." and "The timestamp data type is just an incrementing number and does not preserve a date or a time. To record a date or time, use a datetime data type." Source
And also: "The timestamp syntax is deprecated. This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature." Source

Related

SQL Server: Using date in ISO 8601 format in WHERE clause

In SQL Server 2014 I tried the following query:
select *
from MyTable
where StartDate = '2021-12-31T00:00:00.0000000'
I get this error:
Msg 295, level 16, state 3, row 3
Conversion failed when converting character string to smalldatetime data type.
As far as I can tell this string is in ISO 8601 format, so it should be accepted by SQL Server (I read that this should actually be the preferred format when passing dates to SQL Server).
Is there a way to tell SQL Server to accept this format?
Please note: this query is actually generated by Linq in an Entity Framework Core DataContext, so I can't change the query itself in any way.
Older versions of EF Core did not support smalldatetime.
This was fixed in version 2.2.0 in 2018.
Update your EF Core version to something more recent than 2.2.0.
If you are using a modern EF Core version, then you should file this as a regression bug.
But better yet: don't use smalldatetime in your database design in the first place. Use datetime2(n) or some other appropriate type instead.
There is no good reason for using smalldatetime in a new database design (nor other types like text, ntext, image, timestamp, etc)
And you should be able to run ALTER TABLE to change the column type to datetime2(7) with no compatibility issues unless something else is really horribly designed in your system, in which case you should fix that.
If you really need to expose data as smalldatetime because of some horrible and opaque, but business-critical, binary that you can't rebuild then you can add a VIEW, SYNONYM and other shims to transparently convert datetime2(n) to smalldatetime while the rest of the system can live in modernity.

oracle timestamp 6 convert to sql server datetime2 error

I am using SSIS to convert some oracle data to sql server. I found for Oracle date timestamp6 like this
26-DEC-82 12.00.00.000000000 AM
will cause the conversion in SSIS to fail
Error: Year, Month, and Day parameters describe an un-representable
I think it's because ssis don't know whether it's 2082 or 1982, so don't know how to convert.How can I convert the oracle dates to something with yyyy for the year part?
update: tried to_char function mentioned by Hadi. I can see the year now is 2682 (most of them). I added a pic showing with to_char and original column for plate_date and sold_date columns. As you can see most of the years are 26xx, two exceptions are 18xx. Can someone explain?
In the Oracle Source use an SQL Command to convert TimeStamp to nvarchar using TO_CHAR() function and use the universal data format yyyy-MM-dd HH:mm:ss:
TO_CHAR(SOURCECOLUMN, 'YYYY-MM-DD HH24:MI:SS')
And in SSIS data flow add a derived column with the following expression:
(DT_DATE)[SOURCECOLUMN]
Or add a data conversion transformation and convert the column to date data type.
In SQL Server, the datatype "timestamp" is nothing to do with dates or times.
Microsoft have renamed their old "timestamp" datatype to "rowversion" because it is just an 8-byte number that is used to record a sequence of “row changed” events.
On the other hand Oracle's "timestamp" really is about time because Oracle's "timestamp" extends their "date" datatype. more here.
Unfortunately, SQL Server still recognises "timestamp" as a valid datatype name.
So, I suspect that your error message may have something to do with the timestamp-timestamp homonym.

storing datetime2 in ssis variable

I'm using SQL Server 2012 Enterprise. I have a requirement where I've to store data with DATETIME2 datatype in SSIS Variable. Unfortunately, SSIS variables don't have that data type.
If I'm storing it into datetime data type, I'm losing information. Can anyone help in giving workaround?
PS: My source system is SQL Server 2012 as well and I'm reading the data from column with datetime2 datatype.
SSIS, at least currently, has a "known" shortfall in that the variable value type, DateTime only has a precision to the second; effectively the same as a datetime2(0). If you therefore need to store anything more accurate that a second, such as if you are using datetime and the 1/300 of a second is important or if you are using datetime2 with a precision of 1 or more, the value type DateTime, will not serve your goal.
A couple of different options are therefore to store the value of as a String or numerical value. This does, however, come with it's own problems; most and foremost that neither of these datatypes are date and time datatypes.
It therefore depends what your goal is. I would most likely make use of a String datatype and ensure it has the ISO format ('yyyy-MM-ddThh:mm:ss.nnnnnnn'). If you're then using something like a T-SQL Task you can pass your variable as normal to the task and the data engine will interpret the literal string as a datetime2(7) (or whichever literal precision you used).

Delphi 6, ADO, MS database "Date" field is same as ftWideString

I want to copy elements to a remote MS-SQL database.
I got conversion error on it.
When I checked the ADOTable structure I saw the MS field
WHENCREATED DATE [NULL]
is converted to
ftWideString 10
Hmmmmm....
Is it normal? Or I can set something to Date fields are come as TDateTime?
The Provider is "SQLOLEDB.1"
Its a DATE (yyyy-mm-dd) type which was introduced in SQL Server 2008 as an alternative to the DATETIME type.
Because SQLOLEDB.1 precedes this there is a backward conversion to DBTYPE_WSTR, using an updated provider (SQLNCLI) would be preferable.

Microsoft SQL Server 2005 time of day data type

Is there a data type which represents time of day? Such as a datetime data type without the date.
when i format 41 seconds into a datetime data type this is what I get:
1/1/1900 12:00:41 AM
I'm trying to store a duration of time in a table.
In SQL Server 2008, there is a Time data type which only stores the time. In versions of SQL Server prior to 2008, your only choice is the DateTime data type (and SmallDateTime) which stores both the date and the time. However, there are means in most languages including T-SQL to show the time portion. What are you trying to accomplish?
Not in 2005 no, there are plenty of discussions around on this subject.
This being just one of them

Resources