# Roku Developer Program

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

## 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.

4 Replies
Level 8

## 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
Level 8

## Re: Calculate DateTime Difference

Hi first of all thanks a lot

Can you please provide me sample code
Level 10

## 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 diffDayEND 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.
Level 8

## Re: Calculate DateTime Difference

Ok thanks a lot.I will try