Skip Navigation

[Résolu] Calculate Number of Days Between a Custom Date Field and TODAY

This support ticket is created Il y a 4 années et 7 mois. 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
- 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)

Marqué : ,

This topic contains 2 réponses, has 2 voix.

Last updated by Ed Il y a 4 années et 7 mois.

Assisted by: Luo Yang.

Auteur
Publications
#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!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.