Here is my code:

Date myDate = startTime.Date();       //e.g. myDate =2016-03-01  
Date weekStartDate = myDate.toStartofWeek(); //weekStartDate results 2016-28-02

When myDate equals 2016-03-01 the value of weekStartDate is 2016-28-02. According to my understanding it should be 2016-29-02.

Is this a bug or am I missing something?

1 Answer 1


At least in the US, the week starts on Sunday, not Monday. See Date Methods:

Returns the start of the week for the Date that called the method, depending on the context user's locale.

public Date toStartOfWeek()

Return Value
Type: Date

For example, the start of a week is Sunday in the United States locale, and Monday in European locales. For example:

  • 2
    In other words, if one is getting the wrong value, they should also check their Locale settings.
    – sfdcfox
    Commented Mar 1, 2016 at 22:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .