dates in-between

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Contact:

dates in-between

Post by shadowslash » Fri May 28, 2010 2:20 pm

How would I be able to get the dates in between Date A and Date B?

For example:
Date A is January 4, 2010
Date B is January 10, 2010

Now how would I be able to use Date A and Date B to produce the dates in-between them.

The result should be:
January 5, 2010
January 6, 2010
January 7, 2010
January 8, 2010
January 9, 2010

Has anybody encountered this problem? It has been a real blocker for a project that I'm working on.

Waiting for your answers,
Shedo Chung-Hee Surashu
Parañaque, Philippines
Image
Image

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: dates in-between

Post by jmburnod » Fri May 28, 2010 10:36 pm

Hi ShadowSlash,

I found a way, I hope that it is useful for you

Code: Select all

function DateBetween pStartDay,pEndDay
   put pStartDay into depDate
   put pEndDay into ArrDate
   put depDate into UnedateD
   convert unedateD to seconds
   put ArrDate into UnedateA
   convert unedateA to seconds
   put unedateA-unedateD into difSec
   put difSec/86400 into nbDays
   repeat with i = 1 to nbDays-1
      put unedateD+(i*86400) into OneDay
      convert Oneday to short date
      put Oneday& return after rDateBetween
   end repeat
   delete last char of rDateBetween
   return rDateBetween
end DateBetween
Best

Jean-Marc
https://alternatic.ch

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Contact:

Re: dates in-between

Post by shadowslash » Fri May 28, 2010 10:44 pm

jmburnod wrote:I found a way, I hope that it is useful for you
Just what I needed! Image
Parañaque, Philippines
Image
Image

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: dates in-between

Post by jmburnod » Sat May 29, 2010 10:06 am

Hi,
Just what I needed!
I am happy there
I tested with bissextil year, it work nice

Be careful, i didnt test it with date before eon (1(1/70)

Best

Jean-Marc
https://alternatic.ch

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Contact:

Re: dates in-between

Post by shadowslash » Sun Jun 06, 2010 5:34 am

A quick question about this script, how do I make it also include the starting date and ending date to display among the list?
Parañaque, Philippines
Image
Image

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: dates in-between

Post by jmburnod » Sun Jun 06, 2010 8:35 am

if i understand what you want, this script add the pStartDay before the list and the pEndDay after the list

Code: Select all

function DateBetween pStartDay,pEndDay
   put pStartDay into depDate
   put pEndDay into ArrDate
   put depDate into UnedateD
   convert unedateD to seconds
   put ArrDate into UnedateA
   convert unedateA to seconds
   put unedateA-unedateD into difSec
   put difSec/86400 into nbDays
   repeat with i = 1 to nbDays-1
      put unedateD+(i*86400) into OneDay
      convert Oneday to short date
      put Oneday& return after rDateBetween
   end repeat
   --•• add pStartDay before the list and pEndDay after the list
   --delete last char of rDateBetween
   put pStartDay& return before rDateBetween
   put pEndDay after rDateBetween
   --•••
   return rDateBetween
end DateBetween
Best

Jean-Marc
https://alternatic.ch

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Contact:

Re: dates in-between

Post by shadowslash » Sun Jun 06, 2010 10:24 am

Thanks! Works great!
Parañaque, Philippines
Image
Image

Post Reply