John Davidson

php - I can't put the timestamp from my sql database in the type="datetime-local"

0 comments
Message:


I am trying to put the value of timestamp in the datetime-local value of the input.


This is how I am trying to do it:


<?php $new_datetime = date("c", strtotime($account['foo'])); ?>
<input class="numberinput" type="datetime-local" placeholder="Enter foo" value="<?php echo
`$new_datetime ?>" name="foo" id="foo" required>`

In $new_datetime is this value: 2021-03-17T16:38:00+01:00


this is what i tried:


$begindate = date("d-m-Y", strtotime($account['foo']));
$begintime = date("H:i", strtotime($account['foo']));
$begintijd = $begindate." ".$begintime;
echo $begintijd; // 17-03-2021 16:38 <--- prints this

why does it not put it in value???



My Answer:
It looks like you are using the wrong format for the datetime-local input type. The value for datetime-local input type should be in the format "YYYY-MM-DDTHH:MM", without the timezone offset.

You can try formatting the timestamp in the correct format before setting it as the value for the input field. Here's an example:

php
$new_datetime = date("Y-m-d\TH:i", strtotime($account['foo']));


Then, you can set this formatted datetime as the value for the input field:

php



This should display the timestamp from your SQL database in the correct format for the datetime-local input type.

Rate this post

3 of 5 based on 5337 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us