Dom
Dom

Reputation: 1028

date time mysql for comments section

I have a question regarding Date and Time for MYSQL. Basically I started building a comments section for a web project I have going on. I was building out the DB table and wanted to know how the DB stores the date and time.

For instance if I am in LA and the time is 7:00 PM will it store the comment at 7PM and say that I am from New York obviously and I see the comment its 10 PM so what time will I see the 7PM that wouldnt really make sense. I am wondering how you solve this problem and differentiate between different time-zones.

I am imagining that the server has its own time zone associated with it so all time is delineated from that which would make things a whole lot easier. But is it right that a person sees their time from a post as 10PM when it was made at 7PM. This is all very confusing to me. Any information on how to regularly deal with this issue or if I have one at all will be greatly appreciated. I am building my site using PHP and Codeigniter.

Upvotes: 1

Views: 223

Answers (2)

MasterGberry
MasterGberry

Reputation: 2860

I personally just store the times in the database under an INT ( 11 ) and use the native PHP time() function to get the time, and then you can convert this into a nicer format of a date using some of the PHP functions http://php.net/manual/en/function.date.php you can get the year, month, day, hour, minute, etc.

You then can easily just add or subtract the # of hours (3600 seconds in an hour) depending on the time zone. May be an easier way to do this, but this is how I am currently doing it :)

Upvotes: 1

ceejayoz
ceejayoz

Reputation: 180075

  1. Ask the user their timezone and adjust times accordingly.
  2. Show the timezone with the date ("9pm ET")
  3. Do what StackOverflow does, and say "2 mins ago".

Upvotes: 1

Related Questions