date sepration issue

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
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

date sepration issue

Post by itsmani1 »

i need to separate this date like :
November 5, 2006
Sunday, 12:00 pm

which php function can help me in conversion of this date : 2006-11-05T12:00:00
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Which functions have you looked at already? And why weren't they usable?
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post by amir »

Code: Select all

<?php
	$date = "2006-11-05T12:00:00";	
	$convert_date = strtotime($date);
	echo date("F d, Y", $convert_date).'<br>'.date("l, h a", $convert_date);
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

strtotime can parse the iso 8601 format. But your string is not valid iso 8601. You need to add a zone designator.
If your timestamps are UTC add Z, e.g. 2006-11-05T12:00:00Z
My current timezone is gmt+1 -> 2006-11-05T12:00:00+01:00
...
Even simpler: You can ask date() for the "right" designator
http://de2.php.net/manual/en/function.date.php wrote:P Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3) Example: +02:00

Code: Select all

<?php
$zd = date('P');
$date = "2006-11-05T12:00:00"; 

$convert_date = strtotime($date.$zd);
echo date("F d, Y", $convert_date).'<br>'.date("l, h a", $convert_date);
?>
Post Reply