Search code examples
apache-pig

Month Name in Apache Pig Latin


There must be an easy way to get the month name from a datetime in Pig Latin e.g. 'Jan' for '30/01/2021'? I can't see it documented and haven't turned up the same question anywhere. Many thanks.


Solution

  • You should use the ToString function.

    To customise the format of the string, use the second argument of the function. You can use the patterns from Java.

    Examples:

    For 2021/01/30 use ToString(datetime_field, 'yyyy/MM/dd')

    For Jan use ToString(datetime_field, 'MMM')