toYyyyMmDd

Type:Function
Status:stable
Since:1.0.0
Platform:jsnode
@blackbyte.sugar.shared.datetime

This function allows you to pass any date string or Date instance and get back this one formatted as YYYY-MM-DD. This format is useful when you need to store dates in a database, set a date input value, etc… Under the hood, it make uses of the wonderful Luxon library.

Params

  1. date*-String

    The date (string) to convert to `YYYY-MM-DD`

  2. settings{}TtoYyyyMmDdSettings

    Some settings to configure your parsing

Return

  1. -String

    The date formatted as `YYYY-MM-DD`

Example

import { toYyyyMmDd } from '@blackbyte/sugar/datetime';
toYyyyMmDd('2025-10-15T14:30:00+02:00'); // '2025-10-15'

Settings

  1. formatString

    If you know the format of your date string, you can pass it here. This will make the parsing faster and more reliable. See Luxon documentation for the list of supported tokens.