date question

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
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

date question

Post by qads »

Hi,
I used date("d/m/Y"); to store the current date in the mysql db, so I have dates like 13/10/2002, is there any way I can change them to a different format? e.g. Sunday 13th Oct, 2002

this will really be useful if some one knows how to do it, I could do it one by one but then again....why am I learning PHP? 8O

thanks alot for your time :)

- Qads
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

for complete date() reference see: http://www.php.net/date

here is a line that could work for you:

date("l m dS M, Y");
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Best to use Timestamp. Checkout mktime().
Timestamp are much easier to change the format.
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

thanks guys but i need to convert the old dates in to this format, i could't find any examples on php.net either :/.

thanks
- Qads
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Question

Post by AVATAr »

Do you want to display them with the new format?, or, do you want to store them in the new format?

In both cases, check date();
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Also consider having actual DATE or TIMESTAMP columns in your database instead of storing your dates in VARCHAR ones. Then you can have MySQL do all the work of converting your dates into whatever you want each time you extract them.

http://www.mysql.com/doc/en/DATETIME.html
http://www.mysql.com/doc/en/Date_and_ti ... tions.html

Mac
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

hmm, quite useful links :)...thanks!
Post Reply