Title: Custom date/time format
Last modified: November 7, 2023

---

# Custom date/time format

 *  Resolved [Keith](https://wordpress.org/support/users/keithkhl/)
 * (@keithkhl)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/custom-date-time-format-2/)
 * Hello, I am looking for a way to change date/time template only on the front 
   page for articles written less than 24 hours.
 * Below is my code snippet, but it replaces wordpress’s default date/time setting.
   Would like to know how to call wordpress’s default.
 *     ```wp-block-code
       add_filter('get_the_date', 'meks_convert_to_time_ago', 10, 1); //override date display
       add_filter('the_date', 'meks_convert_to_time_ago', 10, 1); //override date display
       add_filter('get_the_time', 'meks_convert_to_time_ago', 10, 1); //override time display
       add_filter('the_time', 'meks_convert_to_time_ago', 10, 1); //override time display
   
           /* Callback function for post time and date filter hooks */
           function meks_convert_to_time_ago($orig_time) {
       		global $post;
       		$orig_time = strtotime($post->post_date);
       		if (is_front_page() &  (time() - $orig_time) < 60*60*24 ) {
                   return human_time_diff($orig_time, current_time('timestamp')) . ' ' . __('전');
       		} else {
       		return date('Y-m-d', $orig_time);
       		}
       }
       ```
   
 * The last line for calling date(‘Y-m-d’, $orig_time) is an issue here. I removed
   the entire else conditions, then I have unix time (16xxxxxx) instead of real 
   time. Instead of ‘Y-m-d’, as long as I can call wordpress’s default, I believe
   I can work this out.
 * Plz let me know if there is any solution or workaround. Thx.

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

 *  Thread Starter [Keith](https://wordpress.org/support/users/keithkhl/)
 * (@keithkhl)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/custom-date-time-format-2/#post-17179806)
 * The snippet is inspired by this post. [php – ‘Time ago’ display in WordPress blog archive – Stack Overflow](https://stackoverflow.com/questions/70978588/time-ago-display-in-wordpress-blog-archive)
 * I only modified it to joint if conditions.
 *  Thread Starter [Keith](https://wordpress.org/support/users/keithkhl/)
 * (@keithkhl)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/custom-date-time-format-2/#post-17179812)
 * Got the solution from here.
 * [php – Get default date format in wordpress – Stack Overflow](https://stackoverflow.com/questions/28251972/get-default-date-format-in-wordpress)

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

The topic ‘Custom date/time format’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 1 participant
 * Last reply from: [Keith](https://wordpress.org/support/users/keithkhl/)
 * Last activity: [2 years, 8 months ago](https://wordpress.org/support/topic/custom-date-time-format-2/#post-17179812)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
