• Can anyone help me please with functions.php

    I am using an Events plugin, and a developer kindly updated the dates for me to show 1st, 2nd … etc
    All is fine apart from 11st, 12nd, 13rd
    All other numbers – including 21st, 22nd, 23rd, 31st – show correctly

    This is the php used, is there another line I can add to correct 11st, 12nd, 13rd

    Thank you

    // Event Date Time Format
    
     
    				if( isset( $event['enddate_info'] ) ) {
    					$event_date_time = $event['timespan_short'];
    					$event_date_time = explode( ' @ ', $event_date_time );
    					if( count( $event_date_time ) > 1 ) {
    						
    						$day = $event['enddate_info']['day'];
    						$day_last_digit = substr( trim( $day ), -1 );
    						switch( $day_last_digit ) {
    							case '1':
    								$day .= 'st';
    								break;
    
    							case '2':
    								$day .= 'nd';
    								break;
    
    							case '3':
    								$day .= 'rd';
    								break;
    
    							default:
    								$day .= 'th';
    						}
    						
    						$event_date_time[0] = $event['enddate_info']['weekday'] . ' ' . $day . ' ' . $event['enddate_info']['month'];
    					}
    					$event_date_time = implode( ' @ ', $event_date_time );
    					$event['timespan_short'] = $event_date_time;
    				}
    			}
    		}
    	}
    
    	return $args;
    }
    add_filter( 'ai1ec_theme_args_stream.twig', 'ls_stream_args', 10, 2 );

    [Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]

    • This topic was modified 8 years, 6 months ago by bdbrown.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Could you try this code and tell me if it will work please?

    // Event Date Time Format
    
     
    				if( isset( $event['enddate_info'] ) ) {
    					$event_date_time = $event['timespan_short'];
    					$event_date_time = explode( ' @ ', $event_date_time );
    					if( count( $event_date_time ) > 1 ) {
    						
    						// Getting the day number
    						$day = $event['enddate_info']['day'];
    						
    						// Checking special cases first
    						if (($day == '11') || ($day == '12') || ($day == '13') ){ 
    						   $day .= 'th';  
    						} else {
    							
    							$day_last_digit = substr( trim( $day ), -1 );
    							switch( $day_last_digit ) {
    								case '1':
    									$day .= 'st';
    									break;
    
    								case '2':
    									$day .= 'nd';
    									break;
    
    								case '3':
    									$day .= 'rd';
    									break;
    
    								default:
    									$day .= 'th';
    							}
    						}
    						$event_date_time[0] = $event['enddate_info']['weekday'] . ' ' . $day . ' ' . $event['enddate_info']['month'];
    					}
    					$event_date_time = implode( ' @ ', $event_date_time );
    					$event['timespan_short'] = $event_date_time;
    				}
    			}
    		}
    	}
    
    	return $args;
    }
    add_filter( 'ai1ec_theme_args_stream.twig', 'ls_stream_args', 10, 2 );
    Thread Starter cathlisting

    (@cathlisting)

    Thank you so much! This worked, and now our page is showing the dates correctly! Much appreciated.
    And thank you too to the moderator for amending my post for best-practice.

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

The topic ‘How Dates Appear’ is closed to new replies.