|
 |
Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
|
|
04-23-2012, 05:50 AM
|
PM User |
#1
|
|
New Coder
Join Date: Apr 2010
Posts: 53
Thanks: 3
Thanked 0 Times in 0 Posts
|
Date formatting
I don't know if this is PHP or SQL formatting, so forgive me.
Problem:
Code:
echo "<td>" . date('Y-m-d', $row['EntryDate']) . "</td>";
Result:
Raw:
Code:
2012-04-22 21:55:01
Desired:
Last edited by Name; 04-24-2012 at 04:05 AM..
|
|
|
|
04-23-2012, 07:12 AM
|
PM User |
#2
|
|
New to the CF scene
Join Date: Mar 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
From last many time i found date format for database finally i got that. Thank you...
|
|
|
04-23-2012, 09:36 AM
|
PM User |
#3
|
|
Master Coder
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,532
Thanks: 0
Thanked 503 Times in 494 Posts
|
Quote:
Originally Posted by Name
Problem:
Code:
echo "<td>" . date('Y-m-d', $row['EntryDate']) . "</td>";
|
Solution
Code:
echo "<td>" . date('F j, Y', $row['EntryDate']) . "</td>";
|
|
|
04-23-2012, 12:32 PM
|
PM User |
#4
|
|
New Coder
Join Date: Apr 2010
Posts: 53
Thanks: 3
Thanked 0 Times in 0 Posts
|
Quote:
Originally Posted by felgall
Solution
Code:
echo "<td>" . date('F j, Y', $row['EntryDate']) . "</td>";
|
Result:
|
|
|
04-23-2012, 01:19 PM
|
PM User |
#5
|
|
Supreme Master coder!
Join Date: Mar 2007
Location: N/A
Posts: 14,689
Thanks: 158
Thanked 2,184 Times in 2,171 Posts
|
What do you get when you echo $row['EntryDate'] ?
__________________
Quote:
|
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
|
|
|
|
04-23-2012, 10:44 PM
|
PM User |
#6
|
|
New Coder
Join Date: Apr 2010
Posts: 53
Thanks: 3
Thanked 0 Times in 0 Posts
|
Quote:
Originally Posted by abduraooft
what do you get when you echo $row['entrydate'] ?
|
Code:
2012-04-22 21:55:01
|
|
|
04-23-2012, 10:57 PM
|
PM User |
#7
|
|
Master Coder
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,532
Thanks: 0
Thanked 503 Times in 494 Posts
|
Oops - left out a small piece of the code:
Code:
echo "<td>" . date('F j, Y', DateTime($row['EntryDate'])) . "</td>";
You need to convert the text string returned to a date before you can format it.
|
|
|
04-24-2012, 12:24 AM
|
PM User |
#8
|
|
Super Moderator

Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
|
why not format the date using DATE_FORMAT directly in your mysql query, then there is no need to do it at output in the php code.
|
|
|
04-24-2012, 02:34 AM
|
PM User |
#9
|
|
New Coder
Join Date: Apr 2010
Posts: 53
Thanks: 3
Thanked 0 Times in 0 Posts
|
Quote:
Originally Posted by guelphdad
why not format the date using DATE_FORMAT directly in your mysql query, then there is no need to do it at output in the php code.
|
I would like to keep the time of the entry, however format the result. Would it be better to have 2 fields? One for date. One for time?
|
|
|
04-24-2012, 03:53 AM
|
PM User |
#10
|
|
New Coder
Join Date: Apr 2010
Posts: 53
Thanks: 3
Thanked 0 Times in 0 Posts
|
Quote:
Originally Posted by felgall
Oops - left out a small piece of the code:
Code:
echo "<td>" . date('F j, Y', DateTime($row['EntryDate'])) . "</td>";
You need to convert the text string returned to a date before you can format it.
|
This broke the query and it doesn't show any data in the table.
|
|
|
04-24-2012, 04:04 AM
|
PM User |
#11
|
|
New Coder
Join Date: Apr 2010
Posts: 53
Thanks: 3
Thanked 0 Times in 0 Posts
|
Code:
echo "<td>" . date('D M j, Y', strtotime($row['EntryDate'])) . "</td>";
Here is the solution. Was missing the strtotime function.
|
|
|
04-24-2012, 04:06 AM
|
PM User |
#12
|
|
Super Moderator

Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
|
Perhaps you should look up DATE_FORMAT in the MySQL manual.
|
|
|
04-24-2012, 04:32 AM
|
PM User |
#13
|
|
New Coder
Join Date: Apr 2010
Posts: 53
Thanks: 3
Thanked 0 Times in 0 Posts
|
Date() worked though?
|
|
|
 |
Jump To Top of Thread
| Thread Tools |
|
|
| Rate This Thread |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +1. The time now is 04:25 AM.
|
Advertisement Log in to turn off these ads. |
|
|
|
|
|
|
|
|
|
|