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
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Thu Dec 14, 2006 9:15 am
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
Post
by timclaason » Thu Dec 14, 2006 9:45 am
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
Post
by Begby » Thu Dec 14, 2006 9:49 am
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.
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Thu Dec 14, 2006 10:29 am
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 » Thu Dec 14, 2006 11:25 am
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!
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Thu Dec 14, 2006 7:01 pm
I'm not sure throwing an echo in their is necessarily going to fix the problem.
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Thu Dec 14, 2006 9:34 pm
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:
The \\r in the date formatting escapes the "r", which would otherwise be replaced with an RFC 2822 formatted date string.
Cheers,
Kieran
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Fri Dec 15, 2006 4:23 am
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:
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