Problem · String

Is This Date a Weekend?

Learn this problem
EasySalesforce logoSalesforceFULLTIMEOA
See Salesforce hiring insights

Problem statement

Given a valid calendar date date in exact YYYY-MM-DD form, return true if it falls on Saturday or Sunday. Return false if it falls on Monday through Friday.

Interpret the date with the proleptic Gregorian calendar. The result depends only on the calendar date, not on a time zone or locale.

Function

isWeekend(date: String) → boolean

Examples

Example 1

date = "2024-06-15"return = true

June 15, 2024 is a Saturday, so the result is true.

Example 2

date = "2024-06-17"return = false

June 17, 2024 is a Monday, so the result is false.

Example 3

date = "2000-01-02"return = true

January 2, 2000 is a Sunday, so the result is true.

Constraints

  • date has exactly ten characters in YYYY-MM-DD form.
  • The year is between 0001 and 9999, inclusive.
  • date is valid under the proleptic Gregorian calendar.

More Salesforce problems

drafts saved locally
public boolean isWeekend(String date) {
    // write your code here
}
date"2024-06-15"
expectedtrue
checking account