2

I need to save a library all 7 days 'open time' and 'close time' , Please suggest how to achieve this?

Currently I have create a database table_lib_hours

-----FIELD-----|--TYPE-------
|day_id        | int(10)     |
|day_name      |varchar(100) |
|day_open_time |TIME         |
|day_close_time|TIME         | 
|last_update   |TIMESTAMP    |

Now my question is

Is there any way to store all 7 day's name in day_name field automatically ?

xkeshav
  • 53,360
  • 44
  • 177
  • 245
  • 1
    I already answered your 2nd question here: http://stackoverflow.com/questions/2086313/insert-am-pm-from-front-side-and-store-in-time-field-of-mysql/2086482#2086482 What's wrong with it? – Decent Dabbler Jan 30 '10 at 08:15
  • See my follow up comment on your other question. – Decent Dabbler Jan 30 '10 at 09:32
  • Lots of downvotes with no explanations... – Ignacio Vazquez-Abrams Jan 30 '10 at 23:02
  • Hmm, I'm not sure what to do I Like PHP. Maybe you should ask this at http://meta.stackoverflow.com That is the site for asking about the do's and don'ts of this site. – Decent Dabbler Jan 31 '10 at 22:02
  • Maybe you should edit this question and remove the 2nd question, so only the 1st question about storing daynames remains? By editing the question you'll probably also get some attention to the question again because it re-appears on the homepage again, if I'm correct. – Decent Dabbler Jan 31 '10 at 22:06

3 Answers3

0
  1. strftime() with a format of %a or %A will give you the weekday name for a date.
  2. Leave it as a normal time in the database and use strftime() with a format of %I or %l combined with %p or %P when displaying it .
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0

it's usually better to keep non formatted or locale independent data inside your app, and let the front end display/format it...

So I don't know if you have to support multiple language in your app, but if it's the case I'd definitely go with a day of week index instead of the day name.

1) there's usually already functions to handle this in DB engines like DAYOFWEEK() in MySQL. 2) it's easier to order when you query it.

for the time i'd go with what fireeyedboy suggested and use STR_TO_DATE to insert your data in the DB and DATE_FORMAT when you fetch back the data

all the functions you need are here

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

t00ny
  • 1,598
  • 1
  • 11
  • 8
0

Use a timestamp in UTC timezone for easier relocation of the server.

In your application, simple format the timestamp for output. When reading in data, use gmmktime().

Flavius
  • 13,566
  • 13
  • 80
  • 126