Format store hours in PHP from MySQL timestamp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • djminus1
    New Member
    • Oct 2008
    • 12

    Format store hours in PHP from MySQL timestamp

    Hi,

    I am struggling to find a methodology for formatting the store hours for a restaurant that I am developing a simple CMS for. I am using codeIgniter, but it's sort of irrelevant.

    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
  • guillermobytes
    New Member
    • Jan 2010
    • 77

    #2
    hi,
    you should google mysql aggregate function GROUP_CONCAT()

    Comment

    Working...