Input date format yyyy-mm-dd

Hi,

I have little problem with date picker in html input field.
When I choose date from picker it show in this format: dd.mm.yyyy but when that record save to database MySQL shows like this:
yyyy-mm-dd , what is the best way to make this working, to write in database date in this format dd.mm.yyyy

there is html:

<label>Date of birth:</label>
<input type="date"  class="form-control" name="date_birth" required />

Open in new window




EDIT:

I am fix that using date("d.m.Y",strtotime($_POST['datum_rodjenja']));
Žan AnđićAsked:
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.

Julian HansenCommented:
Is your date field in the database created as a date type or a varchar / char type?

If you are saving to a database with a field that has the date type then save it in the format the database expects (example: yyyy-mm-dd).

When you retrieve the value and you need it to appear in a specific format you can do so by re-formatting the date
$database_date = // set db date here
$display_date = date('d.m.Y', strtotime($database_date));

Open in new window

The internal representation of the date is how the data is stored in the MySQL database you should not worry about what this looks like.

If you are storing your dates in a char / varchar field then that is different - consider changing to using a date type instead and then do as above.
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
Žan AnđićAuthor Commented:
Hi,

Thank you for answer,

I am storing dates in a varchar field. I have date picker, and in date picker date is showed well. And I replace just this:

$date_of_birth=$_POST['date_birth'];

with this:

$date_of_birth=("d.m.Y",strtotime($_POST['datum_rodjenja']));
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
>>I am storing dates in a varchar field

in general, dates should be stored as dates. unless there are special requirements why it's stored as chars.

as Julian also pointed out, consider to store the values in date data type to increase the data integrity.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Žan AnđićAuthor Commented:
I changed to DATE, and when showing i put

$database_date = // set db date here
$display_date = date('d.m.Y', strtotime($database_date));

Open in new window

0
Julian HansenCommented:
Is there a question in your last post?
0
Žan AnđićAuthor Commented:
Changed to DATE, displaying like I wrote on my previous commentar

Thank you Julian and Ryan
0
Julian HansenCommented:
You are welcome.
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
HTML

From novice to tech pro — start learning today.