Display Month and Year from date field

  • 1
  • 1
  • Question
  • Updated 3 years ago
  • Answered

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?

Photo of Ringoparr

Ringoparr

  • 844 Points 500 badge 2x thumb

Posted 3 years ago

  • 1
  • 1
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,280 Points 50k badge 2x thumb
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))
Photo of Ringoparr

Ringoparr

  • 844 Points 500 badge 2x thumb
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!!!
Photo of Ringoparr

Ringoparr

  • 844 Points 500 badge 2x thumb
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]?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,280 Points 50k badge 2x thumb
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)
Photo of Ringoparr

Ringoparr

  • 844 Points 500 badge 2x thumb
It doesn't like the last variable "A variable declaration must be followed by a type."
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,280 Points 50k badge 2x thumb
right,
change
var MMMDDYYY = $Month & "  " & ToText(Year($DateWords));

to

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

Ringoparr

  • 844 Points 500 badge 2x thumb
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.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,280 Points 50k badge 2x thumb
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)