Click here to Skip to main content
15,893,337 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I have a field called

DateInNumber
------------
6455646445
1337654860
2342141234
6456435634
4745674574
...
..
...

i need out in datetime format.

2014-08-21 16:10:23 format in sql server.

What will be the query?
Posted
Updated 26-Nov-14 0:07am
v2
Comments
Kornfeld Eliyahu Peter 26-Nov-14 6:18am    
What these numbers are? Milliseconds? What the origin of them?
shaprpuff 26-Nov-14 6:27am    
this is oracle numbers i use
TO_CHAR(TO_DATE('01/01/1970 00:00:00', 'MM/DD/YYYY HH24:MI:SS') + DateInNumber/ (60 * 60 * 24), 'MM-DD-YYYY HH24:MI:SS') as DateInDate

but now i need it in SQL.
shaprpuff 26-Nov-14 6:28am    
I think it is milliseconds or seconds can you give me both formulas
King Fisher 26-Nov-14 6:18am    
not Clear !

try like this..
SQL
select cast(SUBSTRING('11122014',1,2)+'/'+SUBSTRING('11122014',3,2)+'/'+SUBSTRING('11122014',5,4) as date)


Updated:
SQL
declare @val as varchar(max)
set @val='11122014101012'
select cast((SUBSTRING(@val,1,2)+'/'+SUBSTRING(@val,3,2)+'/'+
SUBSTRING(@val,5,4)+' '+SUBSTRING(@val,9,2)+':'++SUBSTRING(@val,11,2)+':'+SUBSTRING(@val,13,2)) as datetime)
 
Share this answer
 
v2
Comments
Kornfeld Eliyahu Peter 26-Nov-14 6:16am    
Did you saw the sample numbers in OP?
This formula works for me when datetime numbers are in seconds,

dateadd(s,DateInNumber , '1970-01-01') as DateTimeString
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900