Reply
Displaying date in British format
Old 05-11-2007, 04:58 AM Displaying date in British format
Average Talker

Posts: 23
Hi all

I had a search of the php forum and I found a couple of things but I'm not quite sure how to implement what I found so....

I have a form in an admin section of a website that I submit to a table. It submits the current days date into a date field.

When the page with the info pulled from the table is displayed, it displays the data thus: YYYY-MM-DD

I would prefer it to be DD-MM-YYYY

Now my query is, at what point do I ask the date to be in the desired format?

On submission?
When I SELECT from the database?
When I echo the results?

Thanks for any tips!
Marf is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 05-11-2007, 05:09 AM Re: Displaying date in British format
tripy's Avatar
Fetchez la vache!

Posts: 2,055
Name: Thierry
Location: In the void
On select, it depend of your database. Check the manual for that.
For mysql, go there:
http://dev.mysql.com/doc/refman/4.1/...on_date-format

For doing it in php, use the date() function.
the date function requires an unix timestamp. So either return an unix timestamp from your db (see first point) or use php mktime() function.
http://www.php.net/manual/en/function.date.php
http://www.php.net/manual/en/function.mktime.php
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 05-11-2007, 05:00 PM Re: Displaying date in British format
Webmaster Talker

Posts: 589
Location: Atlanta, GA
The best way is to place the data in the database the way you want it displayed. To do this, you would use the following function:

date('d-m-Y')

This should give you the result you desire.

I have some ideas on how to change the date format on current and old posts. Let me know if you need them.
neorunner is offline
Reply With Quote
View Public Profile
 
Old 05-11-2007, 05:09 PM Re: Displaying date in British format
tripy's Avatar
Fetchez la vache!

Posts: 2,055
Name: Thierry
Location: In the void
I strongly disagree with neoRunner.

If you do that, it means that you store the date on a text format.
It means too that you won't be able to use the database time and date functions when it come to sort or discard some records based on the dates.

Let the db store dates as dates, and learn to use the db function that will allow you to change the way it's displayed.
In the long run, it'll make your life easier.
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 05-11-2007, 05:32 PM Re: Displaying date in British format
Webmaster Talker

Posts: 589
Location: Atlanta, GA
I didn't know of such a function. Can you elaborate?
neorunner is offline
Reply With Quote
View Public Profile
 
Old 05-11-2007, 06:36 PM Re: Displaying date in British format
tripy's Avatar
Fetchez la vache!

Posts: 2,055
Name: Thierry
Location: In the void
Read your dbms manual, and for mysql, read my second post.
There are a full range of date manipulation functions built right into every dbms engines.
Use them !
http://dev.mysql.com/doc/refman/4.1/...on_date-format
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Displaying date in British format
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14268 seconds with 12 queries