473,326 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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
Mar 6 '10 #1
1 3328
hi,
you should google mysql aggregate function GROUP_CONCAT()
Mar 7 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Neal | last post by:
I have a MySQL table with a datetime field that stamps the time the user submitted the form. It works and looks like this: $sql = "INSERT INTO table VALUES(....now())"; On another php page to...
11
by: Rick | last post by:
I am going crazy on how to format a simple date. I have this in my MySQL table. "2005-03-10 08:44:21" and I want it to format out like "3/10/2005" or "03/10/05" but I seem to be going at it the...
1
by: teqnow | last post by:
I created a table with a timestamp field called "date_added", and it defaults to the NOW function. Any way to change the format to get it to default to the current date instead? I really don't want...
2
by: David | last post by:
Hi, Has anyone had this problem ? I am using MySQL ODBC 3.51 Driver, with MS Access 2003 and MySQL 4.1.11 standard log. I created my tables in MS Access, then exported them via ODBC to an...
4
by: hph | last post by:
Okay, another trivial matter that I can't solve. I have a variable - $lastdate - that is the latest date any record in a MySQL database was updated. Its MySQL format is TIMESTAMP. If I say I...
6
by: marc | last post by:
hi im trying to convert Date() into a unix timestamp so i can stick the result into a mysql db, please help!
67
by: James Harris | last post by:
I have a requirement to store timestamps in a database. Simple enough you might think but finding a suitably general format is not easy. The specifics are 1) subsecond resolution - milliseconds...
0
by: Serious_Practitioner | last post by:
Good day, and Happy New Year! I'm trying to teach myself some PHP and MySQL and the project that I've decided to build will be dependent on queries involving comparisons of dates. I'd like some...
2
by: daknightuk | last post by:
Hi people, I'm working on a project where I have a MYSQL database containing a database table which has opening hours of a load of businesses in it. Each business has 4 TIME fields for each day...
6
by: alexs | last post by:
hi, I'm moving a mysql database over to using db2 V9.5 The database is used by our radius server to store network accounting information from our switches. One parameter is the length of a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.