Jump to content

Formating Date in a php - xml File


rilana

Recommended Posts

Hi guyes

 

I am having troubles formatting my dates the right way. I know it's supposed to be easy, but I dont get what I do wrong.

 

<?php 

$link = mysql_connect("localhost","_","_");
mysql_select_db("_");

$query = 'SELECT  *  FROM news';
$results = mysql_query($query);
$line = 2;


echo "<?xml version=\"1.0\"?>\n"; 
echo "<news>\n"; 
echo "<n>" . $line. "</n>\n"; 
while($line = mysql_fetch_assoc($results)) {

$datum = date("d-m-Y");
   
   echo "<event>\n";
   echo "<title>" . $line["titel"] . "</title>\n"; 
   echo "<date>" . $line["datum"] . "</date>\n";
   echo "<text>" . $line["text"] . "</text>\n"; 
   echo "<url>" . $line["link"] . "</url>\n";
    echo "</event>\n";
}

echo "</news>\n";

mysql_close($link);


?>

Can anyone tell me please what I'am doing wrong? Thanks a lot, Rilana

 

Link to comment
https://forums.phpfreaks.com/topic/130315-formating-date-in-a-php-xml-file/
Share on other sites

Hi guyes

 

I am having troubles formatting my dates the right way. I know it's supposed to be easy, but I dont get what I do wrong.

 

<?php 

$link = mysql_connect("localhost","_","_");
mysql_select_db("_");

$query = 'SELECT  *  FROM news';
$results = mysql_query($query);
$line = 2;


echo "<?xml version=\"1.0\"?>\n"; 
echo "<news>\n"; 
echo "<n>" . $line. "</n>\n"; 
while($line = mysql_fetch_assoc($results)) {

$datum = date("d-m-Y");
   
   echo "<event>\n";
   echo "<title>" . $line["titel"] . "</title>\n"; 
   echo "<date>" . $line["datum"] . "</date>\n";
   echo "<text>" . $line["text"] . "</text>\n"; 
   echo "<url>" . $line["link"] . "</url>\n";
    echo "</event>\n";
}

echo "</news>\n";

mysql_close($link);


?>

Can anyone tell me please what I'am doing wrong? Thanks a lot, Rilana

 

 

what does your output look like?

 

$datum = date("d-m-Y") would be 27-10-2008

but you've never formatted $line['datum'] (assuming that's a date also).

hy, my output looks like 2008-10-10 unstead of 10-10-2008.

 

I thaught I was formating the echo "<date>" . $line["datum"] . "</date>\n";

by saying that datum is supposed to be formated lke that... $datum = date("d-m-Y");

 

What do I have to do to formate the $line['datum'] ? sorry I am a bit of a dummy....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.