Page 1 of 1

Bus schedule/timetable

Posted: Mon Feb 21, 2011 6:02 pm
by sprdnja
Hi everyone,

I have to implement bus time table in this way:
Every bus drives every second day from the day chosen.
Let's say: If xx bus goes every second day from 23rd February to 30th June to Spain (23rd, 25th, 27th...),
How can I check if let's say on 14th May there is bus to Spain?

I started with odd and even numbers: if it starts from the even day than there is array of months with number of days, but what if Feb has 29days (every 4th year) instead of 28... I'm totally confused here.

Is there any other way of implementing this?

Re: Bus schedule/timetable

Posted: Mon Feb 21, 2011 7:55 pm
by Weirdan
you may try DatePeriod class

Re: Bus schedule/timetable

Posted: Tue Feb 22, 2011 5:21 am
by sprdnja
Hi, thanks for your help.

I have mis-minded date functions.

The easiest way of implementing this is to calculate days between start date and the date you looking at, and then check if the result can be divided by 2

Code: Select all

if(($days_difference % 2) == 0){
 //the bus will run today
}else{
 //the bus won't run today
}