0

I was working on a project where I have to update or change the Date & Time.

As I am using PHP-MYSQL, I have no idea how can I replace the input field with already saved (previous) Date & Time.

I wrote below code but it is not working.

Let value in numeric_time = 1539666333

<input type="datetime-local" value="<?php echo date('Y-m-dG:i', $numeric_time); ?>">

2 Answers 2

1

HTML5 datetime-local input field requires the format to be:

  • A date.
  • The literal string "T".
  • A time.

Example: 2018-12-31T23:59

So as Per above format your input should be as follows:

 <input type="datetime-local" value="<?php echo date('Y-m-d\TH:i', $numeric_time); ?>">

Tip: You can also check your console in your devTools for seeing what is the required format for this date input, if your console is clear then your format is correct otherwise it will display warning as below then you can test the various formats, for you ablove solution is correct:

The specified value "2018-10-16T07:05AM" does not conform to the required format.  The format is "yyyy-MM-ddThh:mm" followed by optional ":ss" or ":ss.SSS".      jquery.min.js:3 
Sign up to request clarification or add additional context in comments.

1 Comment

welcome @JohnDoe, dont forget to upvote if you find it useful.
0

You can set it like this.

    <?php 
    $numeric_time = 1539666333;
    $dateFromTime = date('Y-m-d', $numeric_time).'T'.date('H:i', $numeric_time);
    ?>

    <input type="datetime-local" value="<?php echo $dateFromTime; ?>">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.