Help creating array of date/time periods

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
james_withers
Forum Newbie
Posts: 6
Joined: Mon Aug 04, 2008 8:03 am

Help creating array of date/time periods

Post 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
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Help creating array of date/time periods

Post 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;
}
 
james_withers
Forum Newbie
Posts: 6
Joined: Mon Aug 04, 2008 8:03 am

Re: Help creating array of date/time periods

Post by james_withers »

Thanks, I appreciate the reply, I will check it out.
Post Reply