Page 1 of 1

Help creating array of date/time periods

Posted: Mon Aug 04, 2008 8:23 am
by james_withers
Hi,

I am trying to write a program to help with my trading. I need to create an array of dates for different trading time frames. For example I need a function that will take a date/time as an argument and create an array of all of the days moving forward for a year, not including bank holidays and weekends (this bit I am struggling to get my head around). I need to do the same for every four hour period, every hour period and every 15 minute period too. I dont need to project the smaller time periods forward for a year, just a month or so would do.
Does anyone have any advice on how this could be achieved, specifically dealing with the weekends and bank holidays? I just cant seem to get my head around it ... :banghead:

Thanks

James

Re: Help creating array of date/time periods

Posted: Mon Aug 04, 2008 7:19 pm
by yacahuma
I found this
http://abledesign.com/programs/holiday_code.php

to check for holidays. And bellow is some code I put together. Dont know if it works

Code: Select all

 
function isHoliday($day)
{
   $d = date('w',$day);
   if ($d != 0 || $d != 6)//0=sunday,6=saturday
     return true;
 
  return false;
 
}
 
$exp  = mktime(0, 0, 0, date("m")  , date("d"), date("Y")+1);
$temp = mktime(0, 0, 0, date("m")  , date("d"), date("Y"));
$dates = array();
while($exp > $temp)
{
 $temp = mktime(0, 0, 0, date("m")  , date("d")+1, date("Y"));
 if (!isHoliday($temp))
     $dates[] = $temp;
}
 

Re: Help creating array of date/time periods

Posted: Thu Aug 07, 2008 5:48 am
by james_withers
Thanks, I appreciate the reply, I will check it out.