Welcome Guest, Not a member yet? Register   Sign In
Format store hours in PHP from MySQL timestamp
#1

[eluser]Unknown[/eluser]
Hi,

I am struggling to find a methodology for formatting the store hours for a restaurant that I am developing a simple CMS for using CI.

Basically, the restaurant owner has a page in his administration section where they can enter their store hours into a form. These hours are stored as timestamps in MySQL. What I want is to format the store hours like they are typically displayed on websites. Here is an example...

Monday-Friday | 7:00am - 10:00pm
Saturday | 7:00am - 2:00am
Sunday | 10:00am - Midnight


I am having the users enter the open and close times for each day of the week individually. This is because I want them to eventually be able to select how they want the hours displayed, and my application would format them for display. Therefore, the database looks like:

mon_open = timestamp
mon_close = timestamp
tue_open = timestamp
tue_close = timestamp
wed_open = timestamp
etc.....


I am struggling to find a way to easily group together days that have the same time. For instance, if monday, tuesday and wednesday all have the same open and close time, the the format should be...

Mon-Wed | open - close

Is there a way to do this without a ton of nested "if" statements? Keep in mind that there may be instances where there ends up being multiple groups of similar hours. Example:

Monday - Wednesday | 7:00a - 12:00a
Thursday - Friday | 8:00a - 2:00a
Saturday | 10:00a - 2:00a
Sunday | 10:00a - 10:00p


Any guidance on how this could be easily accomplished would be great.

Regards,

Kevin


Messages In This Thread
Format store hours in PHP from MySQL timestamp - by El Forum - 03-06-2010, 07:05 AM
Format store hours in PHP from MySQL timestamp - by El Forum - 03-06-2010, 10:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB