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?
 
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
 
Ž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 ChongCommented:
>>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
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
Ž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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.