Page 1 of 1

Format of date time field from database

Posted: Thu Jul 07, 2005 1:30 am
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

Posted: Thu Jul 07, 2005 1:33 am
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;

?>

Posted: Thu Jul 07, 2005 3:45 am
by Nil10
Thanks a lot!, it works.

Posted: Thu Jul 07, 2005 5:53 am
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