PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Troubles With Time Field Format

  1. Seantech
    Member

    I've searched extensively, but haven't found a reasonable solution to my problem. First, the issue:

    I have a custom post type (Events) that I want a start and end time for. Simple. Gravity Forms has a built in Time field to use. Cool. The problem is that the format is "11:30 PM" or "23:30". Not exactly ideal for advanced sorting (I'm using the Types plugin for my custom fields and the Views plugin for the display.).

    I have tons of options, and none of them are working. So please let me know which is easiest/most-robust/whatever:

    1) Strip the colon and AM/PM from the custom field. Great, how would I go about doing that? If it was just "1130" instead of "11:30 AM", that would be much easier to use.

    2) Convert it into a unix timestamp. Good in theory, but then it becomes burdened with a date as well. Which leads to...

    3) Somehow combine date and time into one field.

    4) Try an hour dropdown and a minute dropdown. Ok, I made those. How can I combine them? It looks like the math component only works on number fields, not dropdowns. Oh, and it also supposedly works on Products as well, though that didn't work for me either. If something has numerical values (as these do), then why can't calculations be enabled?

    It's a bit similar to this: http://www.gravityhelp.com/forums/topic/adding-two-values-in-user-notification-shortcode
    but instead of wanting the info for notification purposes, I wish to populate a custom field with the result.

    Anyone have any ideas? Thanks.

    Posted 7 years ago on Wednesday March 27, 2013 | Permalink
  2. I would go with 4). When you say "combine", I think you mean you want to concatenate them into one value which you can then store as a custom field? You can combine the fields using some code and the gform_pre_submission_filter. http://www.gravityhelp.com/documentation/page/Gform_pre_submission_filter

    [php]
    <?php
    // change the 5 here to your form ID
    add_filter('gform_pre_submission_filter_5', 'combine_hh_mm');
    function combine_hh_mm($form){
    	$_POST['input_17'] = $_POST['input_2'] . $_POST['input_3'];
    	return $form;
    }

    This will take the hour from field 2 and the minute from field 3 combine them into one string and store it in field 17 which is a hidden field in your form mapped to your custom field. You need to have a place in your form to store the calculated string. I used field 17. Change your field IDs and form ID to match your situation.

    Posted 7 years ago on Sunday March 31, 2013 | Permalink
  3. Seantech
    Member

    That did the ticket. Plugged that in and did my start time, copied it and did my end time. Everything seems kosher.

    Many thanks.

    Posted 7 years ago on Monday April 1, 2013 | Permalink
  4. You're welcome. Thanks for the update.

    Posted 7 years ago on Tuesday April 2, 2013 | Permalink

This topic has been resolved and has been closed to new replies.