Solved

Modifying display of MySQL Timestamp data in PHP

Posted on 2007-04-08
3
194 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 51

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 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

Webinar: MongoDB® Index Types

Join Percona’s Senior Technical Services Engineer, Adamo Tonete as he presents “MongoDB Index Types, How, When and Where Should They be Used?” on Wednesday, July 12, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7).

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

705 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