Title: Custom function to return date without time
Last modified: December 23, 2022

---

# Custom function to return date without time

 *  Resolved [Reed Sutton](https://wordpress.org/support/users/reedus33/)
 * (@reedus33)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/custom-function-to-return-date-without-time/)
 * Hello I have a custom pods field which stores date and time. I want to store 
   the time but I do not want it displayed on the front end. I am trying to create
   a function to allow me to display as described here: [Code Samples: Return a Calculated Value in a Pods Template – Pods Docs](https://docs.pods.io/code-snippets/return-calculated-value-pods-template/)
 * Is this on the right track?
 * `**function** return_date_only( **$id** ) {`
 * `**$pods** = pods('rebate_applications',**$id**);`
 * `**$date_time** = **$pods**->field('application_date');`
 * `**$date_only** = $date_time->format(M j, Y);`
 * `**return $date_only;**`
 * `}`

Viewing 11 replies - 1 through 11 (of 11 total)

 *  Thread Starter [Reed Sutton](https://wordpress.org/support/users/reedus33/)
 * (@reedus33)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/custom-function-to-return-date-without-time/#post-16316867)
 * Also is there a way to make it work with multiple different pods, not just ‘rebate_applications’?
 * Thanks!
 *  Plugin Support [pdclark](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/custom-function-to-return-date-without-time/#post-16316948)
 * I’m going to sleep at the moment so sorry if this is too short, but the date 
   time string can be parsed to a date integer with [https://www.php.net/manual/en/function.strtotime.php](https://www.php.net/manual/en/function.strtotime.php)
   then parsed back to a string with [https://www.php.net/manual/en/function.date.php](https://www.php.net/manual/en/function.date.php)
 * You can get the post type from the post ID with [https://developer.wordpress.org/reference/functions/get_post_type/](https://developer.wordpress.org/reference/functions/get_post_type/)
 *  Plugin Support [pdclark](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/custom-function-to-return-date-without-time/#post-16317569)
 * [@reedus33](https://wordpress.org/support/users/reedus33/)
 *     ```wp-block-code
       <?php
   
       add_shortcode(
       	'date_only',
       	function( $atts, $content, $shortcode_tag ) {
       		return return_date_only( get_the_ID() );
       	}
       );
   
       function return_date_only( $id ) {
       	$date_time = get_post_meta( $id, 'application_date', true );
       	return date(
       		'M j, Y',
       		strtotime( $date_time )
       	);
       }
       ```
   
 *  Thread Starter [Reed Sutton](https://wordpress.org/support/users/reedus33/)
 * (@reedus33)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/custom-function-to-return-date-without-time/#post-16317596)
 * Great, small modification – can you make it so I pass the field as well – application_date,
 * such that {@ID, application_date, return_date_only}
 * I have some other date time fields I’d like to use the function for.
 * Thanks either way!
    -  This reply was modified 3 years, 5 months ago by [Reed Sutton](https://wordpress.org/support/users/reedus33/).
 *  Plugin Support [pdclark](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/custom-function-to-return-date-without-time/#post-16317622)
 * Are you trying to use this as a magic tag? If so, the format would be `{@application_date,
   return_date_only_for_magic_tag}`, where the first item is the field on the current
   post object, and the second is the function to be used, which takes the date 
   as an argument. The ID would not be used in this case:
 *     ```wp-block-code
       <?php
   
       function return_date_only_for_magic_tag( $date_time ) {
       	return date(
       		'M j, Y',
       		strtotime( $date_time )
       	);
       }
       ```
   
 * See [https://docs.pods.io/displaying-pods/magic-tags/#Passing_values_through_callbacks_and_filters](https://docs.pods.io/displaying-pods/magic-tags/#Passing_values_through_callbacks_and_filters)
 * Or, as a shortcode which takes the attribute `field`, e.g., `[date_only field
   ="application_date"]`:
 *     ```wp-block-code
       <?php
   
       add_shortcode(
       	'date_only',
       	function( $atts, $content, $shortcode_tag ) {
       		return return_date_only( get_the_ID(), $atts['field'] );
       	}
       );
   
       function return_date_only( $id, $field ) {
       	return date(
       		'M j, Y',
       		strtotime( get_post_meta( $id, $field, true ) )
       	);
       }
       ```
   
 * See [https://developer.wordpress.org/reference/functions/add_shortcode/](https://developer.wordpress.org/reference/functions/add_shortcode/)
 * If you have any additional changes to your custom requirement, please try yourself
   first and come with your closest solution.
 *  Thread Starter [Reed Sutton](https://wordpress.org/support/users/reedus33/)
 * (@reedus33)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/custom-function-to-return-date-without-time/#post-16317684)
 * Oh perfect that’s even simpler. Yes I am using it as a magic tag.
 * One more ask – what if I want to add 90 days or 3 months to the date as well?
 *  Plugin Support [pdclark](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/custom-function-to-return-date-without-time/#post-16318170)
 * See [https://developer.wordpress.org/reference/functions/human_time_diff/](https://developer.wordpress.org/reference/functions/human_time_diff/)
 * It takes two Unix timestamps so pass it the values from `strtotime()` and `now()`.
 *  Thread Starter [Reed Sutton](https://wordpress.org/support/users/reedus33/)
 * (@reedus33)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/custom-function-to-return-date-without-time/#post-16318198)
 * Like if the application_date is April 1, 2023, I want to display July 1, 2023…
 *  Plugin Support [pdclark](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/custom-function-to-return-date-without-time/#post-16318204)
 * Read the examples in the linked strtotime() documentation. It supports relative
   date calculations.
 *  Thread Starter [Reed Sutton](https://wordpress.org/support/users/reedus33/)
 * (@reedus33)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/custom-function-to-return-date-without-time/#post-16318255)
 * Thanks – worked. Code below for reference.
 *     ```wp-block-code
       /*
       Returns the date in 3 months within a magic tag.
       Usage: {@field, return_date_three_months}
       https://wordpress.org/support/topic/custom-function-to-return-date-without-time/#post-16316867
       */
   
       function return_date_three_months( $date_time ) {
       	return date(
       		'M j, Y',
       		strtotime( "+3 months", strtotime($date_time) )
       	);
       }
       ```
   
 *  Plugin Support [pdclark](https://wordpress.org/support/users/pdclark/)
 * (@pdclark)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/custom-function-to-return-date-without-time/#post-16318258)
 * Nice work! Thank you for sharing your result.

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Custom function to return date without time’ is closed to new replies.

 * ![](https://ps.w.org/pods/assets/icon.svg?rev=3286397)
 * [Pods - Custom Content Types and Fields](https://wordpress.org/plugins/pods/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/pods/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/pods/)
 * [Active Topics](https://wordpress.org/support/plugin/pods/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/pods/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/pods/reviews/)

 * 11 replies
 * 2 participants
 * Last reply from: [pdclark](https://wordpress.org/support/users/pdclark/)
 * Last activity: [3 years, 5 months ago](https://wordpress.org/support/topic/custom-function-to-return-date-without-time/#post-16318258)
 * Status: resolved