TheFastestTurtle
TheFastestTurtle

Reputation: 149

Display shorter date format

The date is sent from backend in this format:

"2022-01-01T00:00:00.00000"

How to display date without hours/minutes/seconds like this:

2022-01-01?

On my .tsx component I have InputDatepicker:

            <InputDatepicker
              label="Training date"
              value={trainingData?.trainingDate || ''}
            />

Upvotes: 1

Views: 212

Answers (3)

AndriiKrupenko
AndriiKrupenko

Reputation: 1

const newDate = date.slice(0, 10);

Upvotes: 0

Rahul Beniwal
Rahul Beniwal

Reputation: 687

Simple

new Date('2022-01-01T00:00:00.00000').toLocaleDateString('en-CA');

Upvotes: 1

Lajos Arpad
Lajos Arpad

Reputation: 77045

You can get the first element of the result of split, like this:

console.log("2022-01-01T00:00:00.00000".split('T')[0]);

Upvotes: 3

Related Questions