You need get_the_time
, not the_time
to get the date (the latter echo‘s the value). You also need to re-evaluate how you’re trying to calculate the end date – you can’t just “add” the number of days. What if the event length was 3 but the start date was the 31st?
if ( $event_length ) {
// Get the unix timestamp of the post
$post_time = get_the_time( 'U' );
// Increase the timestamp by the event length
$end_time = $post_time + $event_length * DAY_IN_SECONDS;
// Conditional date format depending on if the event ends in the same month
if ( date( 'm', $post_time ) !== date( 'm', $end_time ) )
echo date_i18n( ' - M j', $end_time );
else
echo date_i18n( ' - j', $end_time );
}
Related Posts:
- WordPress returns a wrong date
- Unable to set right time in admin and frontend template
- display month in french in wordpress/php?
- Get date numerical and separate?
- Print last modified date only on posts
- How to get User Time Zone in WordPress?
- Get date function not working
- If Post Published Date or Modified Date is 1 Year or Older, Display Notice on Post Page
- WordPress wrong dates bug
- Can’t add to time? [closed]
- Display Year and Month from custom field + Age Calculator
- Convert custom field date format to “WordPress default”
- Calculate business days
- How to get WordPress Time Zone setting?
- the_date() not working
- Converting timestamps to local time with date_l18n()
- PHP function showing wrong time in WordPress
- How to get year, month and hour in WordPress?
- Archive listing of posts by publish year (multiple years)
- Why does this echo values in the wrong order?
- How to check for WordPress timezone type?
- WP_Query meta_query results date by date
- Convert a date to ISO8601 date format
- wrong php date()?
- Way to display “Yesterday”, “Today”
- Displaying the Month and Year that a page was Created?
- Adding number to date not working [closed]
- Set meta field to publish date + 2 weeks
- How to manually change current date to post date in frontend?
- Convert WordPress date format to jQuery UI Datepicker format
- Converting Y-m-d to a date with a Month name? [closed]
- Find hours between post_date and post_date_gmt
- 3 different times on my WordPress website
- How would I use this filter to change the output of the date format to “Twitter time”?
- Check If Post Was Published More Than 6 Months Ago Using get_the_date
- How do I check or test a WordPress Auto Year Change Script?
- Shortcode function doesnt work without caption
- Using php inside javascript [closed]
- Comparing Dates from custom field
- PHP time function ($today) for GMT +1
- Is there way to toggle the publish date display?
- Hide publish date when update date
- How to detect and handle the time difference between server and user in WordPress?
- Issue in displaying the ongoing event and current events in the post
- No more get_option(‘date_time’) in WordPress 5.5?
- Don’t update modified post date when user add a product review or comment?
- Possible to edit custom date field and display?
- Get posts from year from URL
- Changing Date Format on Custom Meta Data w/shortcode call
- Primary navigation menu with timed items from custom post type
- How to pull date/time in french format for wordpress post?
- Grouping posts by date
- WordPress change post date format from english to japanese
- Ordering / grouping posts by datepicker ACF
- Comparing Dates within plugin using PHP If statement
- Array sorting assistance
- Can i show items based on the day with php?
- Display Current Time using shortcode
- How do I convert a custom field to a php date format? [closed]
- Change date/time format in custom plugin
- How can I send an email using PHP?
- Shortcode putting html such as
- Load post content into iframe
- Editor role cannot save custom theme options
- POSTS list in WordPress by views
- Print number of post (in reverse)
- Use WordPress’s Media Uploader/ Manager in non WordPress php application
- How to check If Oembed is empty or not
- Custom field value not saving when it contains a URL?
- How do I let users upload files to a chosen location?
- Wp-login appears White Screen, Error: Cannot modify header information
- Set WP_query ‘order’ option by another tables value
- how to update and display an option without reloading the page
- Code snippet to show current php version inside “At a Glance” box in admin
- Make textarea required. Help [closed]
- How to Update an old theme for the latest wordpress version
- How to edit the styles for the table of pages/post listed in the admin when you click on pages/posts?
- How can I use custom menus with a Bootstrap WordPress theme?
- how to show images without passing it to timthumb.php file for resizing
- How to redirect outgoing links via my own website
- How to implement __() function in my theme’s php file?
- In PHP how do I make my navigation bar show certain links to admins only?
- Display a custom name when the user has no name settle in his account
- Why can’t I connect to the wordpress install page with Nginx?
- Discount in the specific product title using keyword ( Woocoommerce )
- WordPress generates weird permalinks
- WordPress search query, how to modify the sql
- Make a full-width wordpress page
- Modify post image in full size
- Putting hyperlinked and non-hyperlinked text in one line, centered, on .php [closed]
- Need Quick Help With Product Category Page
- how to remove replicating a tag inside loop?
- WP Admin Bar – Get current theme name as custom menu title
- split searchresults into different topics?
- ajax form function error
- Simple Probléme in wordpress
- How to store the_post_thumbnail() value in a variable
- Redirect posts to post editor page based on query string
- How do I stylize selected comments?