Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
subhalaxmi
Level 7

Calculate DateTime Difference

Hey Guys

I am new to roku development.

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 as soon as possible.
0 Kudos
4 Replies
RokuMarkn
Level 7

Re: Calculate DateTime Difference

The simplest way is probably to reformat the strings as ISO 8601 strings, then convert to roDateTimes with roDateTime.FromISO8601String, then convert to seconds with roDateTime.AsSeconds and finally subtract the seconds and divide by 86400.

--Mark
0 Kudos
subhalaxmi
Level 7

Re: Calculate DateTime Difference

Hi first of all thanks a lot

Can you please provide me sample code
0 Kudos
Komag
Level 9

Re: Calculate DateTime Difference

Following info here: http://sdkdocs.roku.com/display/sdkdoc/ifDateTime
I came up with this (untested):

FUNCTION getDateDiff(myISODate1, myISODate2) AS INTEGER ' dates are ISO 8601 strings
date1 = CreateObject("roDateTime")
date2 = CreateObject("roDateTime")
myDate1 = date1.FromISO8601String(myISODate1)
myDate2 = date2.FromISO8601String(myISODate2)
myDate1Sec = myDate1.AsSeconds()
myDate2Sec = myDate2.AsSeconds()
diffSec = myDate2Sec - myDate1Sec
diffDay = diffSec\86400 ' Using \ instead of / will return an integer, ignoring remainder/fraction/decimal
RETURN diffDay
END FUNCTION

But I've never used roDateTime, so I might be doing it wrong. And I don't know how to get your dates into ISO 8601 strings in the first place.
0 Kudos
subhalaxmi
Level 7

Re: Calculate DateTime Difference

Ok thanks a lot.I will try
0 Kudos