Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

Wp Shortcode

Calcula fecha de expiración

// Add Shortcode
function date_difference( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'exp-date' => '',
		),
		$atts
	);

	$exp_date = $atts['exp-date'];
	$start_date = new DateTime($exp_date);
	$current_date = new DateTime("now");
	$displayed_year = date_diff($current_date, $start_date)->y;
	$displayed_months = date_diff($current_date, $start_date)->m;
	$displayed_days = date_diff($current_date, $start_date)->d;
	$years = $displayed_year. ' years';
	$months = $displayed_months. ' months';
	$days = $displayed_days. ' days';
	if ($current_date < $start_date) {
		return "Expires in: {$years}, {$months}, {$days}";
	} else {
		return "Expired: {$years}, {$months}, {$days}";
	}

}
add_shortcode( 'diffecha', 'date_difference' );