Welcome Guest, Not a member yet? Register   Sign In
Display Date
#1

[eluser]clintonbeattie[/eluser]
Hi,

I've just started the development of a blog app (I know there's already a couple out there, it's for learning purposes).

I haven't build the Admin area so I'm inserting content into phpmyadmin.

My question is, how do I change the formatting of my date in the view. My date is in this format 2009-03-17.
How do I get it to output as 17th March 2009 or any other of a variety of ways.

Thanks so much.

C
#2

[eluser]pistolPete[/eluser]
Use a standard unix or mysql timestamps to store the date.
Then you can use the Date helper to transform the date between different formattings.
#3

[eluser]davidbehler[/eluser]
If you want to use mysql date/datetime columns, then you should have a look @ date_format()
#4

[eluser]clintonbeattie[/eluser]
Hi,

this is what I have. The first methos outputs the date as it is the the mySQL database, the second is trying to use the info you posted for me.

echo "<p>".date('Y-m-d', strtotime($post['post_date'])) ."</p>";

echo DATE_FORMAT('2006-05-00', '%Y:%m:%d');

The second attempt here displays this error...
Code:
A PHP Error was encountered

Severity: Warning

Message: date_format() expects parameter 1 to be DateTime, string given

Filename: views/blog.php

Line Number: 6

Any ideas? I'm baffled.
#5

[eluser]clintonbeattie[/eluser]
Got it sorted. Amazing.

Thanks so much.

C

One thing though. This is what I use...

Code:
echo "<p>".date('d M Y', strtotime($post['post_date'])) ."</p>";

If I change this to output the day with a suffix of, for example, 6th, 1st, it doesn't work.
Here's my code...

Code:
echo "<p>".date('D M Y', strtotime($post['post_date'])) ."</p>";

This outputs the day as Mon, Tue etc and not 1st,3rd etc.

Any help for this one?
#6

[eluser]xwero[/eluser]
[quote author="modelreject" date="1237313567"]
echo DATE_FORMAT('2006-05-00', '%Y:%m:%d');
[/quote]
00 is not a valid day
#7

[eluser]clintonbeattie[/eluser]
Still doesn't work, even with ‘2006-05-02’. Mmmmm
#8

[eluser]xwero[/eluser]
hum, DATE_FORMAT is a mysql function not a php function.




Theme © iAndrew 2016 - Forum software by © MyBB