Alter periodgen script to get a range of data based on 2 dates ?

 
Hello,
I would alter this script periodgen.mq4
'periodgen'
to get a range of data based on the 2 dates?

Where should I insert this "IF" test to cut data (generated by periodgen. mq4)
- before the starting date dateStart
and
- after the ending date dateEnd

Which datetime's variable should be used in my IF test ?

datetime dateS=D'2005.03.01 00:00:00';
datetime dateE=D'2007.03.01 00:00:00';
// d is the date recorded in the files /databank/XXXXXXYY.hst
if (dateStart<=d && d<dateEnd) {
    ... (part of periodgen.mq4 script filling the the files)
}


Thanks a lot.
Reason: