Format of date time field from database

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
Nil10
Forum Newbie
Posts: 19
Joined: Thu Jun 30, 2005 1:55 pm

Format of date time field from database

Post by Nil10 »

I have used several hours yesterday trying to work this out, and I am stuck with errors.
When it outputs in the right format I plan on making it an url to that season-period.

I have this: <? echo $seasonstart." - ".$seasonend; ?>

Which outputs this: 2005-02-13 00:00:00 - 2005-06-04 00:00:00

but i need this: 13-02-2005 - 04-06-2005
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

Use strtotime function and then date.

Code: Select all

<?php


$seasonstart = date('d-m-Y', strtotime('2005-02-13 00:00:00'));
$seasonend = date('d-m-Y', strtotime('2005-06-04 00:00:00')); 

echo $seasonstart." - ".$seasonend;

?>
00:00:00'));
$seasonend = date('d-m-Y', strtotime('2005-06-04 00:00:00'));

echo $seasonstart." - ".$seasonend;

?>
and then date.

Code: Select all

<?php


$seasonstart = date('d-m-Y', strtotime('2005-02-13 00:00:00'));
$seasonend = date('d-m-Y', strtotime('2005-06-04 00:00:00')); 

echo $seasonstart." - ".$seasonend;

?>
easonstart = date('d-m-Y', strtotime('2005-02-13 00:00:00'));
$season and then date.

Code: Select all

<?php


$seasonstart = date('d-m-Y', strtotime('2005-02-13 00:00:00'));
$seasonend = date('d-m-Y', strtotime('2005-06-04 00:00:00')); 

echo $seasonstart." - ".$seasonend;

?>
p;amp;lt;?php


$seasonstart = date('d-m-Y', strtotime('2005-02-13 00:00:00'));
$seasonend = date('d-m-Y', strtotime('2005-06-04 00:00:00'));

echo $seasonstarthp


$seasonstart = date('d-m-Y', strtotime('2005-02-13 00:00:00'));
$seasonend = date('d-m-Y', strtotime('2005-06-04 00:00:00'));

echo $seasonstart.&qp.net/strtotime]strtotime[/url] function and then date.

Code: Select all

<?php


$seasonstart = date('d-m-Y', strtotime('2005-02-13 00:00:00'));
$seasonend = date('d-m-Y', strtotime('2005-06-04 00:00:00')); 

echo $seasonstart." - ".$seasonend;

?>
trtotime[/url] function and then date.

Code: Select all

<?php


$seasonstart = date('d-m-Y', strtotime('2005-02-13 00:00:00'));
$seasonend = date('d-m-Y', strtotime('2005-06-04 00:00:00')); 

echo $seasonstart." - ".$seasonend;

?>
05-06-04 00:00:00'));

echo $seasonstart." - ".$seasonend;

?>
nend = date('d-m-Y', strtotime('2005-06-04 00:00:00'));

echo $seasonstart." - ".$seasonend;

?>
ttp://php.net/date]date[/url].

Code: Select all

<?php


$seasonstart = date('d-m-Y', strtotime('2005-02-13 00:00:00'));
$seasonend = date('d-m-Y', strtotime('2005-06-04 00:00:00')); 

echo $seasonstart." - ".$seasonend;

?>
0:00:00'));

echo $seasonstart." - ".$seasonend;

?>
.

Code: Select all

<?php


$seasonstart = date('d-m-Y', strtotime('2005-02-13 00:00:00'));
$seasonend = date('d-m-Y'p.net/strtotime]strtotime[/url] function and then [url=http://php.net/date]date[/url].

Code: Select all

<?php


$seasonstart = date('d-m-Y', strtotime('2005-02-13 00:00:00'));
$seasonend = date('d-m-Y', strtotime('2005-06-04 00:00:00')); 

echo $seasonstart." - ".$seasonend;

?>
ime[/url] function and then date.

Code: Select all

<?php


$seasonstart = date('d-m-Y', strtotime('2005-02-13 00:00:00'));
$seasonend = date('d-m-Y', strtotime('2005-06-04 00:00:00')); 

echo $seasonstart." - ".$seasonend;

?>
$seasonend = date('d-m-Y', strtotime('2005-06-04 00:00:00'));

echo $seasonstart.&quote; - ".$seasonend;

?>
rl] function and then date.

Code: Select all

<?php


$seasonstart = date('d-m-Y', strtotime('2005-02-13 00:00:00'));
$seasonend = date('d-m-Y', strtotime('2005-06-04 00:00:00')); 

echo $seasonstart." - ".$seasonend;

?>
nend;

?>
date.

Code: Select all

<?php


$seasonstart = date('d-m-Y', strtotime('2005-02-13 00:00:00'));
$seasonend = date('d-m-Y', strtotime('2005-06-04 00:00:00')); 

echo $seasonstart." - ".$seasonend;

?>
<?php


$seasonstart = date('d-m-Y', strtotime('2005-02-13 00:00:00'));
$seasonend = date('d-m-Y', strtotime('2005-06-04 00:00:00')); 

echo $seasonstart." - ".$seasonend;

?>
Nil10
Forum Newbie
Posts: 19
Joined: Thu Jun 30, 2005 1:55 pm

Post by Nil10 »

Thanks a lot!, it works.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Try to minimize what PHP is doing and keep it to MySQL when possible. MySQL has a DATE_FORMAT function....

Code: Select all

SELECT DATE_FORMAT(date_column, &quote;%d-%m-Y&quote;) AS the_date FROM table_name
Post Reply