date conversion

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 conversion

Post 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
timclaason
Forum Commoner
Posts: 77
Joined: Tue Dec 16, 2003 9:06 am
Location: WI

Date

Post by timclaason »

Does this work?

Code: Select all

$dat = date("F j, Y", $convert_date).'<br>'.date("l, h a", $convert_date);
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Re: date conversion

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

Post 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.
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post 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!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I'm not sure throwing an echo in their is necessarily going to fix the problem.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

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

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