Dear Sir/Madam,
I have a custom date field and I get the value using get_post_meta
$firstBillDate = get_post_meta( $post_id, "wpcf-uprise-first-bill-date", true);
printf("firstBillDate Type: %s<br/>", gettype($firstBillDate));
It returns string, should I convert this to integer and then compare with strtotime(date('Y-m-d')) or there is another method to get the value of custom date field? Please advise the best practice in comparing the date.

Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
Toolset Types custom date field stores the value to database as Unix Timestamp that is why when you fetch the value of the field from database using the WordPress native function get_post_meta() for the field "uprise-first-bill-date" it return you timestamp.
So to compare the current time:
$firstBillDate = get_post_meta( $post_id, "wpcf-uprise-first-bill-date", true);
if($firstBillDate > time() ) {
echo "bill date is in future";
}else{
echo "bill date is passed";
}
More info:
=> hidden link
Dear Minesh,
Unix Timestamp should be in integer type but why the get_post_meta() return as string? Should I need to use intval() function to do the comparison ?

Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
You should not worry about that, the if condition I shared should work.
$firstBillDate = get_post_meta( $post_id, "wpcf-uprise-first-bill-date", true);
if($firstBillDate > time() ) {
echo "bill date is in future";
}else{
echo "bill date is passed";
}