Date format PHP/MySQL

Svetly

New member
Hey guys,
I am a newbie and I need some help - I will be deeply grateful to all that can help me.
The problem is the following - I have a form, which retrieves automatically date from MySQL cell. The problem is, that the date is being retrieved in MySQL's standart format - yyyy-mm-dd. And I want the date to be retrieved dd/mm/yyyy. Can you help?
Thanks in advance!
 
It would be easier if you posted the script or php file that is displaying the date, as it would be difficult to know exactly how the date is being called or how it is stored in the database.

If possible, check the database, to see what the data looks like for the date value, it would be easier to answer you then as well.
 
Dear ANMMark,
I'll try to do this - although I'm not sure if I will manage to.
The data is entered through a hidden field. The script for entering the date is:

<input name="date_msg" type="hidden" id="date_msg" value="<?php echo date('Y/m/d'); ?>">

The date then is substracted from the table with the following script:

<?php echo $row_rsAnn['anDate']; ?>

I don't know if this helps :dknow: - I might not be explaining it properly.
It is really bugging me that I can't resolve it :crash:
Thanks in advance!
 
While I cannot be sure without seeing how the date is stored, it seems as though your echo is the issue.

Change the following code:
Code:
<input name="date_msg" type="hidden" id="date_msg" value="<?php echo date('Y/m/d'); ?>">

To:
Code:
<input name="date_msg" type="hidden" id="date_msg" value="<?php echo date('dd/mm/yyyy'); ?>">

See if that fixes it for you.
 
Dear ANMMark,
Thank you very much for your reply.
The data is stored in my MySQL table in the standart format - yyyy-mm-dd. I don't know how to change that. So when I corrected the code with the one you suggested the result was the following:
Thw date was submitted in the dd/mm/yyyy format but when it was retrieved from the MySQL table it looked rather bizzare - yydd-mm-yy - i.e. - if the submitted date is 17/10/2004, the returned date is 2017-10-20... :tired:
Any duggestions?
Thanks in advance!
 
In this case I would really need to see the script that adds the date to the database, as this would be what you need to change.
 
Might be best to zip it up and attach it here. That way, others can have a look as well, and might be able to pinpoint something, should I miss it.
 
The file you provided simply echos a date function, and formats the date within the form.

There doesn't seem to be any code there, that actually inserts it into the database.
 
Yes, this form inserts automatically the date on which the message is submitted... I tried other formats for submitting the date to the MySQL table but I wrote already what the results were... Any ideas how the problem could be solved? Or at least a place when I can look up for a solution? :smilie3:
ANMMark - thank you very much for your time and for your replies...
 
Here's the problem in regards to this file inserting the data into the database.....there is no database insert query in this file. Therefore, this file itself cannot be the one which enters the data into the database.
 
change <?php echo date('Y/m/d'); ?> to <?php echo date('d/m/Y'); ?>

Since this is indeed the format for the date getting inserted, this is the only place that would define how it gets entered.
 
Right, I solved the problem - the solution was SO simple and it is really frustrating that it didn't come to me in the first place.
I changed the code with the one you suggested, but from previous experience, the date was displayed then all wrong. What was wrong, was that the table in MySQL was set to receive a data - therefore it formatted the input data by the standart MySQL formatting. So I changed the row type to TEXT instead DATA and it worked :dance:
So now, the string submits the echoed data in the format "d/m/Y" and it is entered in the table in the columnt as text. And the formatting problem is solved!
ANMMark - special gratitudes to you for your help and hints that resolved this! Thanks!
 
Last edited:
Not a problem.

I wished I could have helped you more.

Sometimes it's difficult, not know all of the particulars with any given script.

In any case, I'm glad it worked out for you. :)
 
Back
Top