SQL Server - date conversion
Hi,
Select CONVERT(datetime, 0xffff2e4600000000)
This SQL request does not give the correct date when running on my SQL server's installation.
It gives for instance : 1753-01-01 00:00:00.000
How can I fix it ?
Thank you for help
Re: SQL Server - date conversion
Re: SQL Server - date conversion
Quote:
Originally Posted by
Arjay
Quote it
Do you mean something like this : Select CONVERT(datetime, '0xffff2e4600000000') ?
If so, it does not work. It gives an error ==> Échec de la conversion de la date et/ou de l'heure Ã* partir d'une chaîne de caractères.
Re: SQL Server - date conversion
Quote:
Originally Posted by
James West
Do you mean something like this : Select CONVERT(datetime, '0xffff2e4600000000') ?
If so, it does not work. It gives an error ==> Échec de la conversion de la date et/ou de l'heure Ã* partir d'une chaîne de caractères.
The error message 9translated to English) means "Failed to convert date and / or time from a string".
Do you try to convert from hex data rather than a "string"?
Re: SQL Server - date conversion
Quote:
Originally Posted by
James West
Hi,
Select CONVERT(datetime, 0xffff2e4600000000)
This SQL request does not give the correct date when running on my SQL server's installation.
It gives for instance : 1753-01-01 00:00:00.000
How can I fix it ?
Thank you for help
Again: what result do you expect and where comes this magic value 0xffff2e4600000000 from?
Re: SQL Server - date conversion
I am expecting to get a recent date like 2019-09-xx or something in 2020 not for two or three century less
Re: SQL Server - date conversion
Quote:
Originally Posted by
James West
I am expecting to get a recent date like 2019-09-xx or something in 2020 not for two or three century less
Then where does this magic value 0xffff2e4600000000 come from?
Re: SQL Server - date conversion
Quote:
Originally Posted by
James West
I am expecting to get a recent date like 2019-09-xx or something in 2020 not for two or three century less
In such a case the hex (or binary) you would convert from should be look like (according to my SSMS 2014)
0x323031392D30392D33300000000000000000000000000000000000000000 (for the date '2020-09-30')
Re: SQL Server - date conversion
Very interesting !
I will check in this way.
Could you explain more ?
Re: SQL Server - date conversion
Quote:
Originally Posted by
James West
Could you explain more ?
What "more"?
I just read the MSDN (docs.microsoft.com)