[SOLVED] Date Function with time format 2006-02-10T23:00:00Z

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aischallenge
Forum Newbie
Posts: 3
Joined: Fri Feb 10, 2006 9:15 am

[SOLVED] Date Function with time format 2006-02-10T23:00:00Z

Post by aischallenge »

I am trying to convert this time stamp into my time zone (EST), and display it like MM/DD/YY HH:MM PM.

I can't figure out what date function deals with the time zone.

Current time string (from XMLTV):
2006-02-10T23:00:00Z
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

This may help.

Code: Select all

//echo substr('abcdef', 1, 3);  bcd
    //0000-00-00 00:00:00
    //year-mm-dd hh:mm:ss
    $Year = substr($TimeStamp, 0, 4);
    $Month = substr($TimeStamp, 5, 2);
    $Day = substr($TimeStamp, 8, 2);
    $Hour = substr($TimeStamp, 11, 2);
    $Minutes = substr($TimeStamp, 14, 2);
    $Seconds = substr($TimeStamp, 17, 2);
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Are you getting the timestamp from a database?

If so use date_format()

http://dev.mysql.com/doc/refman/5.0/en/ ... tions.html
aischallenge
Forum Newbie
Posts: 3
Joined: Fri Feb 10, 2006 9:15 am

Post by aischallenge »

I could pull the parts out as you describe, and then add / subtract the number of hours to get it into my time zone. However, I feel as though PHP should have a function that deals with this type of timestamp. Since XMLTV is providing it, I can't imagine that I would have to go through so much trouble.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

http://dev.mysql.com/doc/refman/5.0/en/ ... tions.html
CONVERT_TZ(dt,from_tz,to_tz)

CONVERT_TZ() converts a datetime value dt from the time zone given by from_tz to the time zone given by to_tz and returns the resulting value. Time zones are specified as described in Section 5.11.8, “MySQL Server Time Zone Support”. This function returns NULL if the arguments are invalid.

If the value falls out of the supported range of the TIMESTAMP type when converted fom from_tz to UTC, no conversion occurs. The TIMESTAMP range is described in Section 11.1.2, “Overview of Date and Time Types”.

mysql> SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
-> '2004-01-01 13:00:00'
mysql> SELECT CONVERT_TZ('2004-01-01 12:00:00','+00:00','+10:00');
-> '2004-01-01 22:00:00'

Note: To use named time zones such as 'MET' or 'Europe/Moscow', the time zone tables must be properly set up. See Section 5.11.8, “MySQL Server Time Zone Support”, for instructions.
aischallenge
Forum Newbie
Posts: 3
Joined: Fri Feb 10, 2006 9:15 am

Post by aischallenge »

Thanks for your help. I was able to get this to work, using a combination of things.


$sql = "SELECT CONVERT_TZ(s.time,'+00:00','-05:00') as formatted_date.......

$time = date("D M j h:i:s A",strtotime($row['formatted_date']));
Post Reply