Need to use timepicker with "time" database field types (not datetime)

QuestionsNeed to use timepicker with "time" database field types (not datetime)
Melde asked 6 years ago

Greetings,

I have the premium paid version of this excellent phpgrid.

I have several database fields that are 'time' only, not datetime.

I need to be able to integrate the timepicker with these fields. I tried something like this:

$col["formatter"] = "time";
$col["formatoptions"] = array("srcformat"=>'H:i:s',"newformat"=>'H:i:s A',"opts" => array("timeOnly" => true, "timeFormat"=>"hh:mm tt"));

But the timepicker does not show and the fields are not editable.

How can I go about making 'time' fields work with the timepicker?

Thank you.

Thank you.

9 Answers
Abu Ghufran answered 6 years ago

Here you go: demos/integration/timepicker.php

# to make it date time
$col["formatter"] = "datetime";

# opts array can have these options: http://trentrichardson.com/examples/timepicker/#tp-options
$col["formatoptions"] = array("srcformat"=>'Y-m-d H:i:s',"newformat"=>'H:i:s A',"opts" => array("timeOnly" => true, "timeFormat"=>"hh:mm:ss tt"));

Melde answered 6 years ago

I added this code. However the timepicker Still does Not work.

Abu Ghufran answered 6 years ago

Following demo show working example of how to use timepicker:
demos/integration/timepicker.php

You can find and run it in your demo app and downloaded package.
Let me know for any further help.

Juan Manuel Gareli Fabrizi answered 5 years ago

I put that code, and can see the timepicker, but when I update the fields i always get 00:00:00 (but they are OK on database)

What field type should I use in the database???

Abu Ghufran answered 5 years ago

Try this:

$col["formatoptions"] = array("srcformat"=>'H:i:s',"newformat"=>'H:i:s',"opts" => array("timeOnly" => true));

The newformat does not have AM/PM option and it's 24hour time selection.

kim answered 5 years ago

how do i display time as 12 hour time slection.

displays as:
07/14/2015 13:41:33PM

need to display as:
07/14/2015 01:41:33PM

my code:
col["formatter"] = "datetime";
$col["formatoptions"] = array("srcformat"=>'Y-m-d H:i:s',"newformat"=>'m/d/Y H:i:s A',"opts" => array("timeOnly" => FALSE, "timeFormat"=>"hh:mm:ss tt"));

Abu Ghufran answered 5 years ago

You can set:

$col["formatoptions"] = array("srcformat"=>'Y-m-d H:i:s',"newformat"=>'M d Y h:i A',"opts" => array( ));

newformat: small h, and A will show 12 hour with AM/PM option

I had the same issue and the snippet below fixed everything for me EXCEPT how do I not display the seconds? We only want to input and display hours:minutes. Like 23:34 or 09:15

$col["formatoptions"] = array("srcformat"=>'H:i:s',"newformat"=>'H:i:s',"opts" => array("timeOnly" => true));

Abu Ghufran answered 4 years ago

Change:
"newformat"=>'H:i:s'

to:
"newformat"=>'H:i'

Your Answer

7 + 19 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?