locked
DateDiff FirstDayOfWeek argument RRS feed

  • Question

  • User-1312727929 posted

    I had some trouble specifying Monday as the first day of week in the DateDiff function.

    The following syntax does not work:
    Dim myWeekNumber as Int32 = DateDiff("ww",date1,date2,2)

    Compiler Error Message: BC30519: Overload resolution failed because no accessible 'DateDiff' can be called without a narrowing conversion

    However, using the enumeration value (FirstDayOfWeek.Monday) instead of the value (2) does work. I wonder why.

    Tuesday, December 20, 2011 10:30 PM

Answers

  • User-1831219222 posted

    you can do something like this:

    DATEADD(week, DATEDIFF(day, 0, @StartDate)/7, 0)

    test this :

    SELECT DATEADD(week, DATEDIFF(day, 0, getdate())/7, 0)

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 21, 2011 9:58 AM

All replies

  • User-1889364718 posted

    why don't u use some thing like this

     Dim myWeekNumber As Int32 = DateDiff(DateInterval.WeekOfYear, date1, date2, FirstDayOfWeek.Monday)
    Wednesday, December 21, 2011 4:24 AM
  • User-1831219222 posted

    you can do something like this:

    DATEADD(week, DATEDIFF(day, 0, @StartDate)/7, 0)

    test this :

    SELECT DATEADD(week, DATEDIFF(day, 0, getdate())/7, 0)

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 21, 2011 9:58 AM