subhalaxmi
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2015
10:10 PM
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.
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.
4 REPLIES 4

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2015
07:29 AM
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
--Mark
subhalaxmi
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2015
11:32 PM
Re: Calculate DateTime Difference
Hi first of all thanks a lot
Can you please provide me sample code
Can you please provide me sample code

Komag
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2015
01:25 AM
Re: Calculate DateTime Difference
Following info here: http://sdkdocs.roku.com/display/sdkdoc/ifDateTime
I came up with this (untested):
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.
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.
subhalaxmi
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2015
11:58 PM
Re: Calculate DateTime Difference
Ok thanks a lot.I will try