Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
subhalaxmi
Visitor

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 4
RokuMarkn
Visitor

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
Visitor

Re: Calculate DateTime Difference

Hi first of all thanks a lot

Can you please provide me sample code
0 Kudos
Komag
Roku Guru

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
Visitor

Re: Calculate DateTime Difference

Ok thanks a lot.I will try
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.