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
Ron BaasDirecteurAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
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
0
ste5anSenior DeveloperCommented:
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.
0
Ron BaasDirecteurAuthor Commented:
Hi Chris

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

I hope you can help me
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Chris StanyonWebDevCommented:
OK Ron,

Fundamentally, there's nothing wrong with your code. If your date is indeed in the yyyy-mm-dd format, then the rest of your code will work fine:

$originalDate = "2018-04-23";
$newDate = date ("d-m-Y", strtotime ($originalDate));
echo $newDate; // 23-04-2018

Open in new window

However, there's still a little confusion. You're still referring to a database column called pickupdate, but then your code uses a POST variable called pickupdate. The Database and POST are very different things!

There's also a space between $ and _POST (guessing that's a typo here)

As a quick sanity check, do a var_dump of the POST array at the beginning of your code:. Also, whilst debuffing, it makes sense to turn on error reporting:

error_reporting(E_ALL);
ini_set('display_errors', 1);

var_dump($_POST);

$originalDate = $_POST["pickupdate"];
$newDate = date("d-m-Y", strtotime($originalDate));
echo $newDate;

Open in new window

This way you will see exactly what your POST array holds and whether the values are what you expect them to be. You will also get an early warning of any errors in your code.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ron BaasDirecteurAuthor Commented:
Thanks Chris,

It works

regards ron
0
Ron BaasDirecteurAuthor Commented:
thanks Chris
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.