Hi folks,

I am in the midst of updating a clients website, only I am having some trouble using their existing code.

They have a fixed schedule which displays what times the presenters are "on-air"....

I have created some timezone offset's for basic countries and I would like it to take the offset off the set time, which is in the MySQL database.

So basically the time is 2100 - 0000 GMT and the user selects Brazil as their timezone, so it takes -0300 off the time. But the trouble I am having is the result is turning out in negative numbers, so instead of it showing 1800 - 2100, it shows 1800 - -300.
Same thing if the time is say 2100 - 2200 and the user selects USA which adds +0800 onto the time, it ends up as 2900 - 3000.

How can I get PHP to only work within the numbers 0000 - 2359 and have no negative numbers whatsoever?

I was looking into scrapping what they have and using php time()/date(), but that is a hell of alot of work as they have other places relying on the data in the database and parsing it in different ways.

So, any ideas anyone?

Many thanks in advance

If you post your existing code I will show you how to fix this. Basically you will have a set of if statements to check if the value is negative or over 2359, if so then it figures how much over the amount it would be and subtracts or adds it to the next base level.

for example if the 2100 - 0000 gmt - 3hours situation
the if statement would check if the value would be lower than 0000 is so it would store the amount under 0000 and then subtract that from 2400 then display that value ie 2100

Alternatively if the situation were reversed:
0000- 2200 gmt + three hours it would see how much extra over 2400 the value would have left and add it to 0000 so the time would be 0100...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.