Link to home
Start Free TrialLog in
Avatar of Ron Baas
Ron BaasFlag for Netherlands

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
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

You say you have a database column called assignment date, but your code doesn't mention that at all. The only mention of a date is a POST variable called "pickup date" (won't work with a space in the name!!)

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
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.
Avatar of Ron Baas

ASKER

Hi Chris

Sorry, I made a few language mistakes. I have adjusted the question.

I hope you can help me
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Chris,

It works

regards ron
thanks Chris