PHP Wordpress: Store time from input as HH:MM:SS.ms

I have a PHP page within wordpress and am wanting the user to input a time, in the format of HH:MM:SS.fff
Note that 'fff' = fraction of a second, to 3 digits. For example, 1 hours, 30 minutes, 25 seconds and 222 would be. 01:30:25.222
The following process works for integers / floats, but I need to format to be set for a time for this example.
At the top, I get the user_ID and set a variable for existing.
$user_id = get_current_user_id();
$existing_100MRow = ( get_user_meta( $user_id, 'user-100MRow', true ) ) ? get_user_meta( $user_id, 'user-U100MRow', true ) : '';
I then have a form with the following HTML. I've attempted to find the solution, this is why this contains the type as Time.
<label for="user-U100MRow"><strong>100M ROW</strong>
<input id="user-U100MRow" type="time" value="00:00:00" step="1" name="user-U100MRow" value="<?php echo $existing_U100MRow; ?>">
</label>
I then set from the input:
$_100mRow = ( ! empty( $_POST['user-_100MRow'] ) ) ? floatval( $_POST['user-_100MRow'] ) : '';
Then update the user:
wf_insert_update_user_meta( $user_id, 'user-100MRow', $_100MRow);
I would like the user to be able to enter a time in the format of HH:MM:SS.fff , for this to update and then also show the default value .
i
I've since tried the following:
$_100mRow = ( ! empty( $_POST['user-_100MRow'] ) ) ? MICROSECOND(DATE_FORMAT(( $_POST['user-_100MRow'] ),'%H:%i:%s.%f')) : '';
STILL STRUGGLING. SHOWING NULL IN DB.
Answer
Solution:
Something along these lines may help:
switch(!empty($_POST['user-_100MRow'))
{
case true:
$dt = new DateTime($_POST['user-_100MRow']);
break;
default:
$dt = new DateTime();
}
$tformat = $dt->format('H:i:s.u');
update_user_meta(
$user_id,
'user-_100MRow',
$tformat
);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: dompdf image not found or type unknown
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.