[Resolved] issue in inserting a date into custome files
This support ticket is created 2 years, 11 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I am trying to insert a date from a PHP page into the toolset custom field using the below code
//calculate new expiration date add 1 year +3 days
$date9=date("m/d/Y");
$date12 = new DateTime($date9);
$date12->modify('+368 day');
$new_expire= (string)$date12->format('m/d/Y');
$sql_renew_message = "update wp_usermeta set meta_value=".$new_expire." where user_id=".$user_value." AND meta_key='wpcf-expiration-date'";
$result_renew_message = $mysqli->query($sql_renew_message);
the output I got is: 0.000247157686604053
-------------------------------------------------------------------------------------------------
Hello. Thank you for contacting the Toolset support.
When you create custom date field using Types plugin, the value stored within the database is as Unix Timestamp.
What you will have to do is you have to store the value to date custom field as Unix Timestamp. This is just for your information.
Now, the custom code you shared is not actually related to Toolset. We have limitation to offer support for such custom edits as its normal date manipulation with PHP and you will have to check yourself your hire contractor who help you with such custom code.
I'm not sure what output you are mentioned here as I can see you are running a query:
$sql_renew_message = "update wp_usermeta set meta_value=".$new_expire." where user_id=".$user_value." AND meta_key='wpcf-expiration-date'";
$result_renew_message = $mysqli->query($sql_renew_message);
And the result message should be the query time. You will have to get the value of your custom field by firing the select query again to see the updated value. Please kindly note that such custom edits are not supported.
I am not asking you to check my php code, I know it is not included in your support limits. I have added the code only to describe the scenario. just I am asking why the date is stored this way. Even it is not the correct Unix timestamp of the inserted date. because the timestamp of the date 2023/01/05 is 1672907524, not 0.000247157686604053.
and if there is a way to display the date in readable format instead of timestamp.