Hi DW, I have a back-end php file which is an engine for my site and a HTML file which is where the input is shown. the actual html code for the inputs is returned from the backend php file because it get customized there and returned with it data.

How this work is that a user first choose a date from a different date picker input, then the system do a post to my backend php file to retrieve relevant data and it will then return a datetime picker which a user has to now only set the time because we already know the date but at the moment a user is forced to also choose the date again now on the datetime picker input.

So I'm trying to attach the posted date picker input date to a datetime input element that is returned from backend, I'm trying to do this at the backend.This seems to be working if I set the value attribute of datetime picker to the posted value but the issue is that it is not shown inside the input element you still see mm/dd/yyyy --:--:-- but when you do an element inspection you can see the attribute value and the date.

What am I missing? Here is my code

//$searchDate has the posted date from a date picker input element
$rqt = $searchDate . " 00:00:00";// I don't want to set the time yet only the date as it is what we have at the moment
$yw = date("m/d/Y H:i:s", strtotime($rqt));
$xsearchDate = date("m/d/Y H:i:s",strtotime($yw));

// Now I'm setting up the datetime picker input element with this value

<div class='bootstrap-timepicker'><div class='form-group' ><div class='input-group'><input class='timein' onfocus='showthis();' type='datetime-local' class='form-control timepicker' value='".$xsearchDate."'><div class='input-group-addon'><i class='fa fa-clock-o'></i></div></div>

Recommended Answers

All 4 Replies

I’m on my phone so it’s hard for me to explain myself, but you are not setting the value in the proper format. A datetime HTML element needs a value in the following format: 2025-10-01T18:30

You’ll want to do something like this:

echo '<input type="datetime-local" value="' . $dt->format('Y-m-d\TH:i') . '" />';

That’s assuming that $dt is a PHP datetime object. But that’s the way that you would format. Can’t really type more from my phone right now.

Thank you, that really helped. I guess I can't set or show only a date just like it does when you manually set it as you can set manually say something like this 25/10/2025 --:--:-- without setting or showing the time as at the moment if I don't set time it defaults to 12:00 AM?

I think you might want to just be using <input type="date"> which is an input box just for a date, as opposed to <input type="datetime-local"> which is for a date/time combination.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.