now() to string?

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
tommy1987
Forum Commoner
Posts: 92
Joined: Tue Feb 21, 2006 8:35 pm

now() to string?

Post by tommy1987 »

Hi there, I have the following:
2006-04-16 11:38:36
(produced from the now() function)
What I want to be able to do is convert that to user friendly information e.g. 11.38 Sunday 16th April, is there an easy way to do this short of ripping the string apart and writing repetetive if statements to find out what each peice is, eg. 04 = "April" etc..

The data is already ammassed in a database and so changing how it is stored is not an option, hence i need to manipulate it with PHP.

Thanks,, Tom
toasty525
Forum Newbie
Posts: 10
Joined: Wed Apr 05, 2006 12:48 pm

Post by toasty525 »

User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Why can't you convert your database to a more generic format? A couples lines of code could get it done..

short of that, try passing your date into strtotime() (php) which will returns a timestamp and pass that to date() (php).. you may be able to convert your date into a timestamp via UNIX_TIMESTAMP (mysql) during the selection, although I'm not sure..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You'll need to convert the data to a unix timestamp before using date()

UNIX_TIMESTAMP() .. You could also use DATE_FORMAT()
Post Reply