JavaScript date.toDateString() method


The date.toDateString() method in JavaScript returns the date portion of a Date object as a human-readable string, without the time.

Syntax:

date.toDateString();

Returns:

  • A string representing the date in the format: Weekday Month Day Year (e.g., "Tue Oct 22 2024").

Example 1: Getting the Date String of the Current Date

const date = new Date(); console.log(date.toDateString());

Output:

Tue Oct 22 2024

Explanation:

  • The method extracts and formats the date part (day, month, year) from the Date object. In this case, it formats the current date.

Example 2: Getting the Date String for a Specific Date

const specificDate = new Date('December 17, 1995 03:24:00'); console.log(specificDate.toDateString());

Output:

Sun Dec 17 1995

Explanation:

  • The date string Sun Dec 17 1995 is generated from the Date object that represents December 17, 1995.

Example 3: Date Object with Modified Time, toDateString Ignores Time

const dateWithTime = new Date('July 20, 1969 20:18:00'); console.log(dateWithTime.toDateString());

Output:

Sun Jul 20 1969

Explanation:

  • Although the Date object includes both date and time, toDateString() only returns the date portion (ignoring the time: 20:18:00).

Summary:

  • date.toDateString() is useful when you want a clean, human-readable string of just the date without any time information.
  • The output format is standardized as Weekday Month Day Year.