3

I have an issue with datetime.

I have two strings. e.g 24-9-15 and 2-10-15. Both are two strings.

I want to find out the difference (in days) between them.

Can you please help me out?

Piotr Olaszewski
  • 6,017
  • 5
  • 38
  • 65
Developer
  • 103
  • 12

4 Answers4

2

1) Parse the 2 strings to roDateTime objects.

Reference - http://sdkdocs.roku.com/display/sdkdoc/roDateTime

2) get the time in seconds for both dates by doing date1.AsSeconds() and date2.AsSeconds()

3) Subtract the 2 times, so you have the time difference in seconds.

4) Divide this seconds by 3600 to convert into hours, then divide by 24 to convert into days

ie. (seconds/3600) / 24

Akshat Agarwal
  • 2,837
  • 5
  • 29
  • 49
0
date1 = CreateObject("roDateTime")
date2 = CreateObject("roDateTime")
diffInSeconds = date1.asSeconds() - date2.asSeconds()
print "seconds lapsed " diffInSeconds
xskxzr
  • 12,442
  • 12
  • 37
  • 77
Naren
  • 1,504
  • 16
  • 19
0

If those are your strings, I do not think there are any functions that will help you. You may have to do it manually. Still, you can look at the ifDateTime functions and see if they help.

0
Function GetDurationString(totalSeconds = 0 As Integer) As String
remaining = totalSeconds
hours = Int(remaining / 3600).ToStr()
remaining = remaining Mod 3600
minutes = Int(remaining / 60).ToStr()
remaining = remaining Mod 60
seconds = remaining.ToStr()

If hours <> "0" Then
    Return PadLeft(hours, "0", 2) + "hours " + PadLeft(minutes, "0", 2) + "minutes " + PadLeft(seconds, "0", 2) +" seconds"
Else
    Return PadLeft(minutes, "0", 2) + "minutes " + PadLeft(seconds, "0", 2)+" seconds"
End If
End Function

======================================================================

Function PadLeft(value As String, padChar As String, totalLength As Integer) As String
While value.Len() < totalLength
    value = padChar + value
End While
Return value
End Function
Dharman
  • 30,962
  • 25
  • 85
  • 135
Subhasmith Thapa
  • 884
  • 7
  • 11