Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gravity Wiz // Gravity Forms // Time Merge Tags
<?php
/**
* Gravity Wiz // Gravity Forms // Time Merge Tags
*
* Adds {time_hh}, {time_hh:12}, {time_hh:24}, {time_mm}, and {time_am_pm} merge tags.
*
* @version 1.0
* @author Ryan Donovan <ryan@gravitywiz.com>
* @license GPL-2.0+
* @link http://gravitywiz.com/...
* @copyright 2020 Gravity Wiz
*
* Usage:
*
* {time_hh} 12-hour format of an hour with leading zeros
* {time_hh:12} 12-hour format of an hour with leading zeros
* {time_hh:24} 24-hour format of an hour with leading zeros
* {time_mm} Minutes with leading zeros
* {time_am_pm} Uppercase Ante meridiem and Post meridiem
*
*/
add_filter( 'gform_replace_merge_tags', 'gwiz_current_time_merge_tags', 10 );
function gwiz_current_time_merge_tags( $text ) {
$local_timestamp = GFCommon::get_local_timestamp( time() );
$time_hh = date( 'h', $local_timestamp );
$time_hh_24 = date( 'H', $local_timestamp );
$time_mm = date( 'i', $local_timestamp );
$time_am_pm = date( 'A', $local_timestamp );
$text = str_replace( '{time_hh}', $time_hh, $text );
$text = str_replace( '{time_hh:12}', $time_hh, $text );
$text = str_replace( '{time_hh:24}', $time_hh_24, $text );
$text = str_replace( '{time_mm}', $time_mm, $text );
$text = str_replace( '{time_am_pm}', $time_am_pm, $text );
return $text;
}
@frankprim

This comment has been minimized.

Copy link

@frankprim frankprim commented Feb 13, 2021

Hi
I need the function for the date perhaps there is this code already I have only so far nothing found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment