Solved

Modifying display of MySQL Timestamp data in PHP

Posted on 2007-04-08
3
192 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 250 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 50

Assisted Solution

by:Steve Bink
Steve Bink earned 250 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 50

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

749 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