Skip Navigation

[Resolved] Calculate Number of Days Between a Custom Date Field and TODAY

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/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by Ed 5 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#1340515

Ed

I have Products (domain names) with a custom date field of "Registration Date". I want to display the number of days (age) between the the Registration Date and TODAY.

How would I go about that?

Also, please tell me that I can, indeed, go about that.

#1340663

Hello,

It needs custom codes, for example:
1) Add below custom PHP codes into your theme file functions.php:

function Number_of_Days( $atts ) {
    // Attributes
    $atts = shortcode_atts(
        array(
            'field' => 'wpcf-registration-date',
        ),
        $atts
    );
	$registration_date = get_post_meta(get_the_ID(), $atts['field'], true);
	$today = time();
	$res = round(($today - $registration_date) / (24 * 60 * 60) );
	return $res; 
 
}
add_shortcode( 'Number_of_Days', 'Number_of_Days' );

2) Use above custom shortcode like this:

[Number_of_Days]

Please replace "registration-date" with your custom date field "Registration Date" slug.

More help:
https://codex.wordpress.org/Function_Reference/add_shortcode

#1340987

Ed

My issue is resolved now. Thank you!