thecreator
thecreator

Reputation: 163

How to enable type=“date” in every browsers (include phones)

I have one big problem with the date, <input type="date"> doesn't work in Mozilla Firefox but works in IOS, Windows Phone and other browsers.

Is it possible to fix this in Mozilla Firefox and put the format date like this dd-mm-yyyy?

Upvotes: 0

Views: 56

Answers (1)

Misunderstood
Misunderstood

Reputation: 5665

I use date inputs with FireFox. It does not matter. When the form is submitted I still use strtotime() on the submitted date.

$date = strtotime ($_POST['date']);

I have a PHP script that calculates the day between two dates.

Days Between Two Dates

This image is from FireFox:
Days Between Two Dates

<?php
$to = strtotime($_GET['to']);
$from = strtotime($_GET['from']);
if (!$from && !$to){
  $from = '8/21/2001';
  $to = '5/27/2014';
  $answer = "<h2>Number of days between<br/>Tuesday the 21st of August 2001 and<br/>Tuesday the 27th of May 2014 is<br/>4,662 days</h2>";
}
else {
  $days = number_format(intval(($to - $from) / 86400));
  $d1 = date('l \t\h\e jS \of F Y ',$from);
  $d2 = date('l \t\h\e jS \of F Y ',$to);
  $answer = "<h2>Number of days between<br/>$d1 and<br/>$d2 is<br/>$days days</h2>";
  $to = $_GET['to'];
  $from = $_GET['from'];
}
echo <<<EOT
<form method="get" action-"dates2days.php">
From: <input type="date" name="from" value="$from"/><br/>
To:&emsp;&ensp;<input type="date" name="to" value="$to" /><br/>
<input type="submit" value="&emsp;Get Days Between Dates&emsp;"/>
$answer
</form>
EOT;
?>

Upvotes: 1

Related Questions