Gravity Forms – UNIX Timestamp

<?php
add_action( 'gform_post_submission_1', 'be_event_timestamp', 10, 2 );
/**
* Create a UNIX timestamp based on Gform date fields
* @author Bill Erickson
* @link http://www.billerickson.net/code/gravity-forms-unix-timestamp
* @link http://www.gravityhelp.com/documentation/page/Gform_post_submission
*
* 'gform_post_submission' applies to all forms, append form ID to specify
*
* @param array $entry
* @param array $form
* @return array
*/
function be_event_timestamp( $entry, $form ) {
$start_date = get_post_meta( $entry['post_id'], 'be_event_start_date', true );
if( $start_date ) {
$timestamp = strtotime( $start_date );
update_post_meta( $entry['post_id'], 'be_event_start_date_unix', $timestamp );
}
$end_date = get_post_meta( $entry['post_id'], 'be_event_end_date', true );
if( $end_date ) {
$timestamp = strtotime( $end_date );
update_post_meta( $entry['post_id'], 'be_event_end_date_unix', $timestamp );
}
}
view raw gistfile1.aw hosted with ❤ by GitHub

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk