PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Date Field Display Day of The Week.

  1. scc
    Member

    I have a user that would like the day of the week to be displayed on the notification e-mails generated from the date field to show the day of the week. so...

    Event End Date
    04/25/2012 - Wednesday

    ... or something similar.

    Is there an output template for the e-mail that I can modify to get the day of the week from the dat and display it in the notification e-mails or an easier way that I am not finding?

    Thanks.

    Posted 12 years ago on Wednesday April 18, 2012 | Permalink
  2. David Peralty

    There is no built-in way to do this. You would have to use a hook, grab the date selected, and using PHP's date function find out the day of the week and then append that to the notification e-mail details. If you still want to tackle this, I can see about giving you some details on where you might want to start.

    Posted 12 years ago on Wednesday April 18, 2012 | Permalink
  3. scc
    Member

    I do want to tackle this and any info you can provide would be helpful.

    Thanks.
    -Mike

    Posted 12 years ago on Wednesday April 18, 2012 | Permalink
  4. David Peralty

    Okay, so it is a bit more complex than I thought, but here's the gist of what you need to do:

    Note: you can't use the all fields merge tag anymore to be able to make notifications. You'll have to add in each merge tag separately to make up your notification message.

    Create a custom shortcode - http://codex.wordpress.org/Shortcode_API
    This short code will do the heavy lifting. You'll want to use a merge tag to pass the date to your shortcode and your shortcode will pass back the day of the week.

    Your merge tag in your notification will look something like:
    [customdate date={My Date Field:1}]

    Your shortcode will use PHP's date function to figure out the day of the week - http://php.net/manual/en/function.date.php

    And then it will pass that value back to your notification and should be then properly included in the e-mail.

    Let me know if this makes sense and helps.

    Posted 12 years ago on Wednesday April 18, 2012 | Permalink
  5. David Peralty

    Here is an example (for EXAMPLE purposes only) of what you should be looking to add to your functions.php file.

    function customdate_func( $atts ) {
    	extract( shortcode_atts( array(
    		'date' => '',
    	), $atts ) );
    
         $thedate = $date;
         $weekday = date('l', strtotime($thedate));
         $thedate = $thedate . ' - ' . $weekday;
         return $thedate;	
    
    }
    add_shortcode( 'customdate', 'customdate_func' );

    You will need to customize it for your exact needs, but this would basically make it so that something like [customdate date={Field Merge Tag:1}] would return XX/XX/XXXX - WEEKDAY.

    We can't support this code, nor really customize it for your specific needs, but hopefully it will work as a shortcut in achieving your goals.

    Posted 12 years ago on Wednesday April 18, 2012 | Permalink
  6. scc
    Member

    Sweet thanks for the info, this will help a ton (my users thank you too)

    -Mike

    Posted 12 years ago on Wednesday April 18, 2012 | Permalink
  7. Wow! Exactly what I was looking for. The Day of the Week seems to be popular. ;-)

    @Mike: did you succeed in adding the DoW to the notification e-mails? Any chance on sharing? :-)

    Thanks,
    Edde

    Posted 12 years ago on Saturday August 18, 2012 | Permalink
  8. Actually, the whole solution was there. Thanks David!

    I ended up adding some lines to replace the English DoW by Dutch ones - see below.
    Using setlocale(LC_ALL, 'nl_NL'); didn't do the translation trick I needed.

    function customdate_func( $atts ) {
      extract( shortcode_atts( array(
        'date' => '',
      ), $atts ) );
    
      $thedate = $date;
      $weekday = date('l', strtotime($thedate));
      $english = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
      $dutch   = array("maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag", "zondag");
      $weekday = str_replace($english, $dutch, $weekday);
      $thedate = $thedate . ' - ' . $weekday;
      return $thedate;
    }
    add_shortcode( 'customdate', 'customdate_func' );
    Posted 12 years ago on Sunday August 19, 2012 | Permalink
  9. Glad that worked out for you edde. Thanks for the update.

    Posted 12 years ago on Sunday August 19, 2012 | Permalink

This topic has been resolved and has been closed to new replies.