I know it's a newb question, but how do I format specific dates and times?
I've got a date in YYYY-MM-DD format and I'd like to pretty it up, but I can't find a good answer anywhere.
I've done an explode and have the three peices, but how do I convert them?
Formatting date parts
Moderator: General Moderators
Re: Formatting date parts
No need to explode() the date. Convert it into a timestamp using strtotime() http://www.php.net/strtotime, and then format it using date() http://www.php.net/manual/en/function.date.php
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Formatting date parts
Do you want the current date?
Use...
Use...
Code: Select all
<?php
// simple format
echo date('d m Y');
// result
// 09 07 2008
// more details
echo date('l dS M Y');
// result
// Wednesday 09th Jul 2008
?>
Re: Formatting date parts
no, I've got a date I'm pulling in.
Re: Formatting date parts
Then my suggestion should work..
Re: Formatting date parts
In addition to what pytrin has already recommended, you can also format it from within the database query.
http://dev.mysql.com/doc/refman/5.0/en/ ... ate-format
http://dev.mysql.com/doc/refman/5.0/en/ ... ate-format
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Formatting date parts
What format do you have it in? YYYY-MM-DD? You should always store dates and time as a unix time stamp (php, not sql), then you can do whatever you want with it so easily, as php has built in functions.
When storing the current time and date in the database use the php function time();
Then from that you can always use...
NB: The unix timestamp stores time and date and you can use the line of code above to pull out one or the other or both.
When storing the current time and date in the database use the php function time();
Then from that you can always use...
Code: Select all
<?php
echo date('d m Y', *UNIX TIMESTAMP No.*); // or any format of [b]d m Y[/b]
?>