Skip Navigation

[Resolved] Form date showing 1/1/1970

This support ticket is created 5 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 5 years, 4 months ago.

Assisted by: Waqar.

Author
Posts
#1346055

I am trying to: Save a date from a Gravity form field

Link to a page where the issue can be seen: It' in the back end

I expected to see: The date I entered

Instead, I got: 1/1/1970

I have a gravity form which saves a form date to a custom post, but when I view the post to edit it, it shows the date as 1/1/1970

#1346187

Hi Marc,

Thank you for waiting.

During troubleshooting, I noticed that the issue seems to be that the Toolset manages and expects date type fields data to be in a UNIX timestamp format, whereas in the Gravity form's setting, this format is not available. As a result, the "Date" field's value in posts added through Gravity form, are not shown correctly, in the admin area.

To convert the date stored by the gravity form, in the UNIX timestamp format, you can follow these steps:

1. Please select the "YYYY-MM-DD" format in the "Date work carried out" field's settings.
( screenshot: hidden link )

2. The Gravity form offers "gform_after_submission" hook, which can be used to execute a custom function, which can change the format of that date field into UNIX timestamp.
hidden link

Example:


add_action( 'gform_after_submission_1', 'set_date_in_timestamp_format', 10, 2 );
function set_date_in_timestamp_format( $entry, $form ) {

	$req_date = get_post_meta( $entry['post_id'], 'wpcf-date', true );

	if( $req_date ) {
		$timestamp = strtotime( $req_date );
		update_post_meta( $entry['post_id'], 'wpcf-date', $timestamp );		
	}
}

The above code snippet can be added into the active theme's "functions.php" file and after that try to create a new post, using the same gravity form.
( for posts which have been added already, you'll need to manually set the correct date from their post edit screen )

For further assistance with "gform_after_submission" hook, you can consult the Gravity Form's official support team.

I hope this helps and please let me know how it goes.

regards,
Waqar