I just try to set a value datetime for input( It is for change the current value of variable date time), but my html show an error ( seems it's fault about the format):
the code is :
<input type="datetime" name="deadline" required value ='<?php echo date('c', $dateDeadline); ?>'/>
Thx a lot.
If $dateDeadiline
is indeed defined, your should wrap it with strtotime()
.
On the manual
:
string date ( string $format [, int $timestamp = time() ] )
You should provide a timestamp
, not a string date. Consider this example:
<?php
$dateDeadiline = '2014-06-21 12:32:00';
?>
<input type="datetime" name="deadline" required value="<?php echo date('c', strtotime($dateDeadiline)); ?>" />
Using DateTime
Class with timezone:
<?php $date = new DateTime('2014-06-21 12:32:00', new DateTimeZone('America/New_York')); ?>
<input type="datetime" name="deadline" required value="<?php echo $date->format('c'); ?>" />
For list of supported timezones, you can check this link:
You are using single quotes for your value attribute that are conflicting with your PHP code. Try this instead:
<input type="datetime" name="deadline" required value="<?php echo date('c', $dateDeadline); ?>" />