[solved] converting a mysql date to plain english with php

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
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

[solved] converting a mysql date to plain english with php

Post by robster »

I'm stumped, I've spent the last half day browsing through php.net manuals looking at date function etc but can't seem to figure out how to convert my mysql date data which looks like this:

Code: Select all

2005-06-02
into something which looks like this:

Code: Select all

Sunday, 02 June 2005
I know this must seem such a sad call for help, but I'm stuck :( (such a neub still, sigh).

Rob
Last edited by robster on Tue Sep 20, 2005 9:59 pm, edited 1 time in total.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

you have to combine date and gmktime.
the general format of gmmktime is int gmmktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )

to get sunday,02 June 2005 you'd have to do the following..

Code: Select all

date('l d F Y',gmmktime(0,0,0,06,02,2005))
that should do the trick unless i had a typo:-D
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Code: Select all

$date = "2005-06-20";
$parts = explode( "-", $date );
$timestamp = mktime( 0, 0, 0, $parts[1], $parts[2], $parts[0] );
echo date( "l, d F Y", $timestamp );
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

be careful with using 0 as a leading to numbers... php may think you mean octal notation ;)
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post by robster »

Thank you so much. It really works well (and turns out it's actually on a Thursday, not a Sunday ;)).

That explode bit of code is really nice. I'll look into that some more, a very useful function indeed!

I'm interested in what could happen if an 'octal notation' occured !? (sounds... so... medical)


rob
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

[feyd@home]>php -r echo((016).chr(13).(16).chr(13).(0x16));
14
16
22
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post by ryanlwh »

why not

Code: Select all

date('l, d F Y',strtotime($mysqlDate));
Post Reply