Page 1 of 1
[SOLVED] Date Function with time format 2006-02-10T23:00:00Z
Posted: Fri Feb 10, 2006 9:18 am
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
Posted: Fri Feb 10, 2006 9:30 am
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);
Posted: Fri Feb 10, 2006 9:33 am
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
Posted: Fri Feb 10, 2006 9:35 am
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.
Posted: Fri Feb 10, 2006 9:38 am
by Benjamin
Posted: Fri Feb 10, 2006 9:38 am
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.
Posted: Fri Feb 10, 2006 9:56 am
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']));