Ron Baas
asked on
from varchar date yyyy-mm-dd convert in php page to dd-m-yyyy
Hi everyone,
I have a problem. In the database I have a column with a date (varchar (100)
. It is entered in the database as yyyy-mm-dd. the name of the field is "pickupdate". I want to show them on a php page as: dd-mm-yyyy.
But I think I'm doing something wrong because he keeps displaying the date incorrectly.
this is what I had:
-------------------------- ---------- ---------- ---- -------------------------- ---------- -------
$originalDate = $ _POST ["pickupdate"];
$newDate = date ("d-m-Y", strtotime ($originalDate));
echo 'We have received a pick up order for a '. $ _ POST ["yesno"].' to retrieve on '. $newDate.' <br /> <br />';
-------------------------- ---------- ---------- ---- -------------------------- ---------- ---------- ---- ------
I hope someone can help
thank you
I have a problem. In the database I have a column with a date (varchar (100)
. It is entered in the database as yyyy-mm-dd. the name of the field is "pickupdate". I want to show them on a php page as: dd-mm-yyyy.
But I think I'm doing something wrong because he keeps displaying the date incorrectly.
this is what I had:
--------------------------
$originalDate = $ _POST ["pickupdate"];
$newDate = date ("d-m-Y", strtotime ($originalDate));
echo 'We have received a pick up order for a '. $ _ POST ["yesno"].' to retrieve on '. $newDate.' <br /> <br />';
--------------------------
I hope someone can help
thank you
Just a comment:
I have a problem. In the database I have a column with a date (varchar (100)).Indeed. This is a severe design issue. You should correct that.
ASKER
Hi Chris
Sorry, I made a few language mistakes. I have adjusted the question.
I hope you can help me
Sorry, I made a few language mistakes. I have adjusted the question.
I hope you can help me
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Chris,
It works
regards ron
It works
regards ron
ASKER
thanks Chris
In PHP, if you have a date string in the yyyy-mm-dd format, then you can very easily use the DateTime object:
$originalDate = "2018-04-23";
$myDate = new DateTime($originalDate);
And then when you want to echo it out, you pass a format string into the format() method:
echo $myDate->format("d-m-Y");
To give you specific answers, you may want to clarify the question a little more