Play with Week, Month, Current/Fiscal Year #'s with Apex Salesforce

Apex Oct 4, 2014

NOTE: Please find difference between 'w' & 'W' below


  • **Current Week #** in **Current Year** `'w')`
  • **Current Week #** in **current Month** `'W')`
  • NOTE: Please find difference between 'w' & 'W' above


  • To get **Current Month** as Integer `'M')`
  • To get **Current Month** as semi string i.e, **Jan, Feb, Mar** and so on `'MMM')` `'MMM')`
  • To get **Current Month** as full string i.e., **January, February** and so on `'MMMM')`
  • Year

  • Current Year as **XXXX** => `'Y')`
  • Current Year as **XX** => `'YY')`
  • NOTE: Format methods returns as String, from string convert into respective dataType


  • **AM/PM** => `'a')`
  • **Hour** in Day **(00-23)** => `'a')`
  • **Hour** in Day **(01-24)** => `'k')`
  • **Hour** in AM/PM **(00-11)** => `'a')`
  • **Hour** in AM/PM **(01-12)** => `'a')`
  • **Minute** in **Hour** => `'m')`
  • **Second** in **Minute** => `'s')`
  • **MilliSecond** in **Minute** => `'S')`
  • **Time Zone** => `'z')`
  • Display Date in Different Types as follows,

    Magic with Apex Dates with DAYS
    Use Case Syntax Output
    Day in Week'F') Integer
    Day in Month'd') Integer
    Day in Year'D') Integer
    Day as Week'E') SUN, MON, TUE

    Note For all above methods GMT timezone is default. In order to get results as per your Timezone pass TIMEZONE as extra parameter.

    For e.g., IST, PST, EDT etc.. so methods looks like'd', 'IST')

    Use Case Syntax Output
    Use Case Syntax Output
    Use Case Syntax Output

    Phanindra Mangipudi

    Salesforce, Lightning Web Componets, Node.Js, Angular 2+, Bootstrap