3

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

5

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

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

Signature
public Date toStartOfWeek()

Return Value
Type: Date

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

1
  • 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 .