?
Solved

Modifying display of MySQL Timestamp data in PHP

Posted on 2007-04-08
3
Medium Priority
?
195 Views
Last Modified: 2013-12-12
I am pulling a value from a MySQL timestamp column into a php script. When It displays nicely, but there are two problems I need to fix. First, it's an hour behind since my hosting company is in a different time zone. Second, it displays military time instead of 12 hour time. So, how can I mold the displayed data? In other words,  the current display is "2007-04-08 14:25:02" but I want it to read as "2007-04-08 3:25:02 PM". What is the best way to accomplish this? Thank you so much!
0
Comment
Question by:smetterd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
Yuval_Shohat earned 1000 total points
ID: 18873362
the format of the timestamp would be:
select DATE_FORMAT(YourTimeStamo,'%Y-%m-%d %r') from YourTable
the time zone is bit more tricky. check this link from the mysql manual:
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_convert-tz

havent checked it out but it should be something like:
select DATE_FORMAT(CONVERT_TZ(YourTimeStamp,'Host's TimeZone','Your TimeZone'),''%Y-%m-%d %r') from YourTable

-=Yuval=-
0
 
LVL 51

Assisted Solution

by:Steve Bink
Steve Bink earned 1000 total points
ID: 18873572
Since you're using PHP, you might want to take a look at the functions on that side of the coin:

http://www.php.net/manual/en/ref.datetime.php

Specifically:

http://www.php.net/manual/en/function.date-default-timezone-set.php

PHP will manage the time zone information for you so long as you tell it what to expect at the begining.  Set your default timezone according to your server's time, then use the time zone-related PHP functions to automatically adjust times and timestamp fields.
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 18873574
To change the default format in which date/times are displayed in PHP, check this function:

http://www.php.net/manual/en/function.date.php
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this article, we’ll look at how to deploy ProxySQL.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question