Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interpret HTML5 input date value using PHP

Tags:

html

php

input

I need to let the users pick a date (preferable in the format dd/mm/yy) and I decide to try out new HTML5 input date type. However I don't know how to interpret the value it gives on the server side. The value I get is yyyy-mm-dd. How can I do this?

What if the user uses an older browser that does not support it, how will they enter the date?

like image 412
Dharman Avatar asked Dec 06 '12 15:12

Dharman


People also ask

How can I get HTML date from PHP?

$d=mktime(11, 14, 54, 8, 12, 2014); echo "Created date is " . date("Y-m-d h:i:sa", $d);

Which html5 attributes can be used with html5 date input type to limit date selection?

The max attribute specifies the maximum value (date) for a date field. Tip: Use the max attribute together with the min attribute to create a range of legal values. Tip: To set or return the value of the min attribute, use the min property.

How can set input type date in mm/dd/yyyy format using HTML?

To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.


1 Answers

  1. Just convert the date using PHP's date functionality (date(), DateTime, etc)

    $datetime = new DateTime('2012-12-06');

    $new_date = $datetime->format('d/m/Y');

  2. They will see a plain text field. It will be up to you to make sure they enter a validate date.

like image 128
John Conde Avatar answered Sep 23 '22 20:09

John Conde