# DateTime issue?

**URL:** <https://forum.xojo.com/t/datetime-issue/85233>\
**Category:** Bugs and Feature Requests\
**Created:** [May 4, 2025, 7:55pm UTC](https://forum.xojo.com/t/datetime-issue/85233 "2025-05-04T19:55:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexandre\_Cunha](https://forum.xojo.com/user_avatar/forum.xojo.com/alexandre_cunha/32/1221_2.png) [@Alexandre\_Cunha](https://forum.xojo.com/u/Alexandre_Cunha)\
**Post date:** [May 4, 2025, 7:55pm UTC](https://forum.xojo.com/t/datetime-issue/85233/1 "2025-05-04T19:55:26Z")

</div>

Hi!

I’ll appreciate any help you guys can give me!

I need to sum mili-seconds to a “timecode”  
The timecode is this: “00:04:53,595” and i want to sum “16” mili-seconds to it.  
The result should be “00:04:53,611”, right?

To avoid the need to managing sums like “23:59:59,999” + 55ms, i opted to use DateInterval to do it for me.

Here is part of my code:

Dim prev\_timeCodeEnd as string = “00:04:53,595”  
Dim h, m, s, ms As Integer  
Dim diffTime As Integer = 16 // ms  
Dim timeCode As String

h = Val(NthField(prev\_timeCodeEnd,“:”,1)) // 0  
m = Val(NthField(prev\_timeCodeEnd,“:”,2)) // 4  
s = Val(NthField(NthField(prev\_timeCodeEnd,“:”,3),“,”,1)) // 53  
ms = Val(NthField(NthField(prev\_timeCodeEnd,“:”,3),“,”,2)) // 595

Var di As New DateInterval  
di.Nanoseconds = (diffTime)\*1000000 // 16000000

Var d1 As New DateTime(2025, 1, 1, h, m, s, (ms\*1000000) )

and so on…

// at this point, just looking for code logic, the nanosecond of d1, should be 595000000, right?  
WRONG! inspecting di.nanosecond, the value is 595000028 // why this extra 28???

What i’m doing wrong? Am i?

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [May 4, 2025, 8:09pm UTC](https://forum.xojo.com/t/datetime-issue/85233/2 "2025-05-04T20:09:49Z")

</div>

For timecodes avoid DateTime.  
Convert all to ms, and handle the ms.  
For presentation have a function to convert ms to string as “hh:mm:ss,nnn”.

---

<div class="post-metadata">

**Author:** ![AlbertoD](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@AlbertoD](https://forum.xojo.com/u/AlbertoD)\
**Post date:** [May 4, 2025, 8:18pm UTC](https://forum.xojo.com/t/datetime-issue/85233/3 "2025-05-04T20:18:16Z")

</div>

> [@Alexandre\_Cunha](#):
>
> WRONG! inspecting di.nanosecond, the value is 595000028 // why this extra 28???
> 
> What i’m doing wrong? Am i?

d1.nanosecond is 595000028 because is pulling the information from the d1.SecondsFrom1970 that is a double. Is the same as:

```auto
var test as Double = 1735711493.595

```

you will get 1735711493.5950000286102295

Doubles are not precise. You need to do as Rick said or some other way.

> **Alexandre's Code**
>
> ```auto
> Dim prev_timeCodeEnd As String = "00:04:53,595"
> Dim h, m, s, ms As Integer
> Dim diffTime As Integer = 16 // ms
> Dim timeCode As String
> 
> h = Val(NthField(prev_timeCodeEnd,":",1)) // 0
> m = Val(NthField(prev_timeCodeEnd,":",2)) // 4
> s = Val(NthField(NthField(prev_timeCodeEnd,":",3),",",1)) // 53
> ms = Val(NthField(NthField(prev_timeCodeEnd,":",3),",",2)) // 595
> 
> Var di As New DateInterval
> di.Nanoseconds = (diffTime)*1000000 // 16000000
> 
> Var d1 As New DateTime(2025, 1, 1, h, m, s, (ms*1000000) )
> //d1.nanosecond = 595000028
> 
> ```
