Page 1 of 1

date conversion

Posted: Thu Dec 14, 2006 9:15 am
by itsmani1
Hi

here is my date: 2007-03-02T13:05:00
i want to convert it to normal date like:
March 2, 2007
Friday, 1:05 pm


i am using:

Code: Select all

$zd = date('P');
	$convert_date = strtotime($val['EVENTDATE'].$zd);
	$dat = date("F d, Y", $convert_date).'<br>'.date("l, h a", $convert_date);
but getting :
March 02, 2007
Friday, 10 am

Date

Posted: Thu Dec 14, 2006 9:45 am
by timclaason
Does this work?

Code: Select all

$dat = date("F j, Y", $convert_date).'<br>'.date("l, h a", $convert_date);

Re: date conversion

Posted: Thu Dec 14, 2006 9:49 am
by Begby

Code: Select all

$zd = date('P');
	$convert_date = strtotime($val['EVENTDATE'].$zd);
	$dat = date("F j, Y", $convert_date).'<br>'.date("l, g:i a", $convert_date);
If the time is still coming out wrong, then the time part of your date is not converting correctly with strtotime(), I have no idea why it came out as '10' with the formatting you had.

FYI, the above solution took me all of 10 seconds to look up on php.net/date. Give that a try next time or print out the php cheat sheet found in the php resources sticky.

Posted: Thu Dec 14, 2006 10:29 am
by itsmani1
how can i change server time? i have SSH access so what if i change server time and then it will start working i guess.

Posted: Thu Dec 14, 2006 11:25 am
by amir
Try this,

Code: Select all

<?php
	$zd = date('P');
    $convert_date = strtotime($val['EVENTDATE'].$zd);
    echo $dat = date("F d, Y", $convert_date).'<br>'.date("l, h:i a", $convert_date); 
?>
BOL!

Posted: Thu Dec 14, 2006 7:01 pm
by RobertGonzalez
I'm not sure throwing an echo in their is necessarily going to fix the problem.

Posted: Thu Dec 14, 2006 9:34 pm
by Kieran Huggins
You need to remove the T in the middle of the date, and you also need to choose the right formatting options for date()

While you're at it, you don't need two date functions when a little double escaping will do:

Code: Select all

$date = "2007-03-02T13:05:00";
$date = date("F j, Y<b\\r/>l, g:i a", strtotime(str_replace('T',' ',$date)));
echo $date;
echos:

Code: Select all

March 2, 2007<br/>Friday, 1:05 pm
The \\r in the date formatting escapes the "r", which would otherwise be replaced with an RFC 2822 formatted date string.

Cheers,
Kieran

Posted: Fri Dec 15, 2006 4:23 am
by itsmani1
Kieran Huggins wrote:You need to remove the T in the middle of the date, and you also need to choose the right formatting options for date()

While you're at it, you don't need two date functions when a little double escaping will do:

Code: Select all

$date = "2007-03-02T13:05:00";
$date = date("F j, Y<b\\r/>l, g:i a", strtotime(str_replace('T',' ',$date)));
echo $date;
echos:

Code: Select all

March 2, 2007<br/>Friday, 1:05 pm
The \\r in the date formatting escapes the "r", which would otherwise be replaced with an RFC 2822 formatted date string.

Cheers,
Kieran
thanks its working now