none
How to add fraction of seconds to Date Time? RRS feed

  • Question

  • Dear Friends,

    I know that Second, Minute, Hour, day, Month & year can be added to Date, by using function "DateAndTime.DateAdd() function; for example; adding 2 seconds to the "Date1"

     DateAndTime.DateAdd(DateInterval.Second,2,Date1)

    I want to add milliseconds to Date and then I want to use " datePart(DateInterval. , Date)" to get the Year, month..... second  and milliseconds (Or as fraction of Second) to use in other calculation.

    Can you please help?

    Thanks

    VKSBK


    A Real Novice Programmer !

    Sunday, September 15, 2019 3:58 PM

Answers

All replies

    • Marked as answer by V.K.S.B.K Monday, September 16, 2019 9:27 AM
    Sunday, September 15, 2019 4:06 PM
  • Hi Castorix31,

    Thanks for the reply; I tried your method and was able to add milliseconds...

    Module Module1
     Sub Main()
    
    Dim DateTest1 As Date = #9/15/2019 10:30:00 AM#
    Dim SecAddedDate As Date
    
     For i = 1 To 20
                SecAddedDate = DateTest1.AddMilliseconds(100 * i)
                Console.WriteLine("Adding 100 MilliSeconds to 10:30:00 am  = " & SecAddedDate & vbCrLf)
            Next
    
      End Sub
    End Module

    Now, please let me know how to get the "added milliseconds" from the "SecAddedDate", like what we get using " datePart(DateInterval. , Second, 'Date')" ? 

    I couldn't find any function for getting the "Millisecond" from Date.

    Could you please help me on this one also?

    Thanks

    VKSBK


    A Real Novice Programmer !

    Sunday, September 15, 2019 5:25 PM
  • I couldn't find any function for getting the "Millisecond" from Date.

    See : How to: Display Milliseconds in Date and Time Values
    • Marked as answer by V.K.S.B.K Monday, September 16, 2019 9:27 AM
    Sunday, September 15, 2019 5:42 PM
  • Hi Castorix,

    Thanks for the help.

    VKSBK


    A Real Novice Programmer !

    Monday, September 16, 2019 9:28 AM