Converting Attain decimal datetime field

mscott
Member Posts: 4
I'm exporting a Navision Attain 3.60 date field into SQL. The exported field looks like 63,255,909.417785. Does anyone know what SQL calculation I can run to convert it to a human readable date and time?
0
Comments
-
Which tool you are using for exporting data from Navision? There must be some wrong conversion.0
-
I'm using a Microsoft SQL DTS Transform Data Task. If I look at the field using Object Designer I see 63,255,909.417785. I get the same thing when I export it into SQL.
There are two other fields in that table that contain the date and the time but they are not always populated so I was hoping to export this field that is always populated. Apparently, it is being stored as a Navision internal format.0 -
If you mean fields 'TimeStamp' - it is timestamp not date and time...
Can you post table definition in Navision and which fields you want transfer?
Thanks0 -
The "Starting Date-Time" field in the "Prod. Order Line" table is an example of a Navision field that displays a date/time value, but is stored internally as a decimal. Here's a way to convert the decimal into a SQL datetime when your language of choice is T-SQL:
SELECT DATEADD(ms,CAST(pol."Starting Date-Time" * 1000000 AS bigint) % 86400000, DATEADD(day, ROUND(pol."Starting Date-Time" / 86.4,1,1) - 723180, '1980-01-01')) AS StartingDateTime FROM dbo."<CompanyName>$Prod_ Order Line" AS pol
0 -
The tip on how to convert the Decimal to DateTime was very useful. Here is the inverse method to convert DateTime to Decimal
The following SQL:
SELECT cast('2015-09-22 14:27:01.223' as DATE) as TheDate
,Cast('2015-09-22 14:27:01.223' as time) as TheTime
,((DATEDIFF(day,'1980-01-01',cast('2015-09-22 14:27:01.223' as DATE)) + 723180) * 86.4)
+ (DATEDIFF(ms,'0:00',Cast('2015-09-22 14:27:01.223' as time)) / 1000000.0) as TheDateAsDecimal
,DATEADD(ms,CAST(63610151.221223000 * 1000000 AS bigint) % 86400000,
DATEADD(day, ROUND(63610151.221223000 / 86.4,1,1) - 723180, '1980-01-01')) TheDecimalAsDate
Will result in:0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions