JavaScript Date Snippets

The JavaScript snippet collection contains a wide variety of ES6 helper functions. It includes helpers for dealing with primitives, arrays and objects, as well as algorithms, DOM manipulation functions and Node.js utilities.

  • Days ago

    JavaScript, Date

    Calculates the date of n days ago from today as a string representation.

  • Days from now

    JavaScript, Date

    Calculates the date of n days from today as a string representation.

  • Max date

    JavaScript, Date

    Returns the maximum of the given dates.

  • Min date

    JavaScript, Date

    Returns the minimum of the given dates.

  • Week of year

    JavaScript, Date

    Returns the zero-indexed week of the year that a date corresponds to.

  • Day name

    JavaScript, Date

    Gets the name of the weekday from a Date object.

  • Date of tomorrow

    JavaScript, Date

    Results in a string representation of tomorrow's date.

  • Date of yesterday

    JavaScript, Date

    Results in a string representation of yesterday's date.

  • Calculates the difference (in months) between two dates.

  • Unix timestamp from date

    JavaScript, Date

    Gets the Unix timestamp from a Date object.

  • Last date of month

    JavaScript, Date

    Returns the string representation of the last date in the given date's month.

  • Converts an integer to a suffixed string, adding am or pm based on its value.

  • Number of days in month

    JavaScript, Date

    Gets the number of days in the given month of the specified year.

  • Date from Unix timestamp

    JavaScript, Date

    Creates a Date object from a Unix timestamp.

  • Date difference in days

    JavaScript, Date

    Calculates the difference (in days) between two dates.