Bus schedule/timetable

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
sprdnja
Forum Newbie
Posts: 2
Joined: Mon Feb 21, 2011 5:17 pm

Bus schedule/timetable

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Bus schedule/timetable

Post by Weirdan »

you may try DatePeriod class
sprdnja
Forum Newbie
Posts: 2
Joined: Mon Feb 21, 2011 5:17 pm

Re: Bus schedule/timetable

Post 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
}
Post Reply