Discussions

Expand all | Collapse all

Display Month and Year from date field

  • 1.  Display Month and Year from date field

    Posted 07-26-2016 17:32

    I have a generic date field.  I'd like it to display MONTH YYYY i.e. JULY 2016.

    Tweaking the date field i am able to get close (JULY 1 2016) but the date still shows 1.  Is there a formula that can get me there?



  • 2.  RE: Display Month and Year from date field

    Posted 07-26-2016 17:38
    Here is some code to use

    var date DateWords = [My Date Field];
    var text Month = Case(Month($DateWords),
    1, "January",
    2, "February",
    3, "March",
    4, "April",
    5, "May",
    6, "June",
    7, "July",
    8,"August",
    9,"September",
    10,"October",
    11,"November",
    12,"December");

    $Month & "  " & ToText(Year($DateWords))


  • 3.  RE: Display Month and Year from date field

    Posted 07-26-2016 17:52
    That worked great, Mark! I had to adjust the type of field to be a Formula - Text.  I assumed it should be a date formula field but was wrong.  Thanks for helping again!!!


  • 4.  RE: Display Month and Year from date field

    Posted 08-02-2016 17:02
    I've got a curveball to add to the mix. Is it possible to adjust this formula to default to n/a when no date is listed in the [My date field]?


  • 5.  RE: Display Month and Year from date field

    Posted 08-02-2016 17:14
    sujre, no problem

    var date DateWords = [My Date Field];
    var text Month = Case(Month($DateWords),
    1, "January",
    2, "February",
    3, "March",
    4, "April",
    5, "May",
    6, "June",
    7, "July",
    8,"August",
    9,"September",
    10,"October",
    11,"November",
    12,"December");

    var MMMDDYYY = $Month & "  " & ToText(Year($DateWords));

    if(IsNull([My Date Field]), "n/a", $MMMDDYYY)


  • 6.  RE: Display Month and Year from date field

    Posted 08-02-2016 17:46
    It doesn't like the last variable "A variable declaration must be followed by a type."


  • 7.  RE: Display Month and Year from date field

    Posted 08-02-2016 17:51
    right,
    change
    var MMMDDYYY = $Month & "  " & ToText(Year($DateWords));

    to

    var text MMMDDYYY = $Month & "  " & ToText(Year($DateWords));


  • 8.  RE: Display Month and Year from date field

    Posted 08-02-2016 18:39
    I need one more if variable.  If the My Date Field occurred on or before 1977, default to "blank".  I've spent an hour tweaking the formula by myself but haven't gotten anywhere.


  • 9.  RE: Display Month and Year from date field

    Posted 08-02-2016 18:48
    var date DateWords = [My Date Field];
    var text Month = Case(Month($DateWords),
    1, "January",
    2, "February",
    3, "March",
    4, "April",
    5, "May",
    6, "June",
    7, "July",
    8,"August",
    9,"September",
    10,"October",
    11,"November",
    12,"December");

    var MMMDDYYY = $Month & "  " & ToText(Year($DateWords));

    if(
    IsNull([My Date Field]), "n/a",
    Year([My Date Field]) <= 1977, null,
    $MMMDDYYY)