Skip Navigation

[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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 2 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#2256677

Dears,

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
-------------------------------------------------------------------------------------------------

But I have used the same code in w3 PHP compiler

$date9=date("m/d/Y");
$date12 = new DateTime($date9);
$date12->modify('+368 day');
$new_expire= (string)$date12->format('Y/m/d');
echo $new_expire;

the output I got is: 2023/01/05 (which is the correct date)

What is wrong with it ??

#2257393

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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.

#2259023

Dear Minesh,

Thank you for your reply,

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.

#2259025

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I already shared with my reply:
=> https://toolset.com/forums/topic/issue-in-inserting-a-date-into-custome-files/#post-2257393

That you will have to get the field value using the get_post_meta() to get the value of field wpcf-expiration-date.
=> https://developer.wordpress.org/reference/functions/get_post_meta/