[Other] Forminator: Strange Date Format in Notification Email {date_dmy}

When using the {date_dmy} in the notification email it returns a strangely formatted date like “5/7/2022”. I have set a proper date format in the general WordPress settings, but this has no effect so far. 

How can I fix this? Thanks in advance :)

  • Adam
    • Support Gorilla

    Hi Konstantin Schultes

    I hope you’re well today!

    The “dmy” part of the {date_dmy} means “day month year” so the order of the date parts is correct in your notification. The “5/7/2022” is July 5th 2022 and it’s one of quite common formats.

    But currently Forminator doesn’t read format (for notifications) from WordPress settings. Instead it offers two formats only “date_dmy” and “date_mdy” where the only difference is the order of date parts. The actuall date is processed through WP core function “date_i18n()” without additionally reading WP settings – which results in such date.

    This was set this way because we needed (upon requests) the choice of whether it should be day-month-year or mont-day-year regardless of whatever date is set in site settings.

    However, I agree that this may be causing confusion and other issues sometimes and I’ve already:

    – reported it to our Forminator Team; it’s not a bug but it certainly is something that could use significant improvement so I hope they’ll be able to improve it with one of future releases

    – and asked our developers if some “patch”/workaround would be possible for now so you could set exactly the format that you need.

    I’d appreciate some patience as they are dealing with a lot of complex tasks on daily basis and their response time may be a bit longer than ours here on support forum but we’ll update you here soon with more information.

    Best regards,
    Adam

  • Prashant
    • Staff

    Hi Konstantin Schultes

    I hope you are doing well.

    We have worked on your issue and found a solution. Please add a must-use plugin to your site’s wp-content/mu-plugins folder like this https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins, then add the following code to the plugin’s php file:

    function wpmudev_change_submission_time_format( $message ) {
    	$placeholders = array(
    		'{date_wp_format}'     => date( get_option('date_format') )
    	);
    	return str_ireplace(
    		array_keys( $placeholders ),
    		array_values( $placeholders ),
    		$message
    	);
    }
    
    add_filter( 'forminator_custom_form_mail_admin_message', 'wpmudev_change_submission_time_format' );
    add_filter( 'forminator_replace_variables', 'wpmudev_change_submission_time_format' );

    After adding the code please use {date_wp_format} macro instead of {date_dmy} to get the date in the format set in the general WordPress settings.

    We recommend to test this on the dev/staging version first before putting it on the live site.

    Hope it will solve your problem.

    Kind Regards
    Prashant