Jump to content
Killersites Forums

Change the date format Mysql - php


Recommended Posts


<?php do { ?>

<?php echo $row_RsEventos['titulo']; ?>

Date: <?php echo $row_RsEventos['fecha']; ?>
Place: <?php echo $row_RsEventos['lugar']; ?>
Time: <?php echo $row_RsEventos['hora']; ?>

<?php echo $row_RsEventos['comentarios']; ?>

<?php } while ($row_RsEventos = mysql_fetch_assoc($RsEventos)); ?>

home | administration | contact    Copyright ? Germ?n Marcano 2009

Edited by edoplaza
Link to comment
Share on other sites

EDIT - go to my edit at the bottom of the post.


No one else has answered so I will offer a little more information, but my PHP and MySQL knowledge is not much; I was hoping falkencreative would answer the question properly.


Your page display has this code


<?php echo $row_RsEventos['fecha']; ?>


which just repeats what is in the database field 'fecha', so perhaps one solution is to change the format in the database, not in the PHP code which displays it on the page.


If you look at this example:-



You will see a form for submission of data which has a date already inserted with a date format echo date("d M Y"); ?> and the database stores this as text (Field: Date; Type: text) and the display of the data in the table at the bottom of the page just shows the text of the date that the database stored. You can see from the dates in the display that the format changes half way down because I changed the date format in the top submission form.


My Date is stored as text but you probably have the database storing date in a date format. You don't show how you get the dates into the database; either change the date format in the form you use to input into the database or go into the database and change the date format there. MySQL date is always stored in the YYYY-MM-DD format and it's complicated to reformat it so it may be easier to change the database Type to Text and then the PHP for the page should output the same text as the database.


Editing the Type for the Field in MySQL is relatively simple and you would then have to edit the previous database entries manually but future date entries as text would be repeated as text by the PHP code.


I expect that there is a way to take the date format from the database and change it to another format with PHP for the table display but falkencreative will have to answer that.


EDIT: I've been experimenting and this code worked for me:-


date('d-m-Y', strtotime($row['fecha'])) but I was testing with a different database and a different form


so where you have

<?php echo $row_RsEventos['fecha']; ?>


in your PHP file I think you need


<?php echo date('d-m-Y', strtotime($row['fecha'])); ?>


Try it.

Edited by Wickham
Link to comment
Share on other sites

Finally, I found a solution:


I was trying to use the DATE_FORMAT function, but it didn't work (still don't know why)


I then changed this:


echo $row_RsEvents['column_date'];


Into this:


$formatted_date= $row_RsEvents['column_date'];

echo date("d-m-Y",strtotime($formatted_date));


and it works perfectly









Sorry Wickham, I didn't see your last edit. I am glad we both came to the same solution! (but yours is better than mine ;))

Edited by edoplaza
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...