Latest Number of Consecutive Weeks

I recently posted a similar question about getting the latest number of consecutive days.
I thought with that information I'd be able to do the same for consecutive weeks, but I was wrong...
I tried some queries using a calendar table, but no luck with getting the right results.
Hate to ask again, but I've been stuck on it for the last 4 hours, can't seem to figure it out.
I have a habit tracking app.
I need the latest number of consecutive entries, by week.
Here is some sample data:
DECLARE @entries TABLE (ID INT IDENTITY, habitID INT, date DATETIME)
INSERT INTO @entries (habitID, date) VALUES
(1, '20150218'),(1, '20150225')
DECLARE @habits TABLE (habitID INT, habitStartDate DATE, habitEndDate DATE)
INSERT INTO @habits (habitID, habitStartDate, habitEndDate) VALUES
(1, '2015-02-16',NULL)
There is 1 habit, with 2 entries.
The resulting query should return: 2
This is because the last 2 weeks have had entries, and since this week is still current, we have until the end of the week to make an entry.
But let's say this week goes by, and there have been no entries.
Then next week, the result from the same query should return: -1

Here's what I did:
alter table calendar add HabitWeekStart DATETIME
alter table calendar add HabitPrevWeekStart DATETIME
alter table calendar add HabitWeekEnd DATETIME
alter table calendar add HabitPrevWeekEnd DATETIME
alter table calendar add HabitWeekEndTS DATETIME
alter table calendar add HabitPrevWeekEndTS DATETIME
update calendar
SET
HabitWeekStart = DATEADD(HOUR,27,WeekStart ),
HabitPrevWeekStart = DATEADD(HOUR,27,PrevWeekStart),
HabitWeekEnd = DATEADD(HOUR,27,WeekEnd ),
HabitPrevWeekEnd = DATEADD(HOUR,27,PrevWeekEnd ),
HabitWeekEndTS = DATEADD(HOUR,27,WeekEndTS ),
HabitPrevWeekEndTS = DATEADD(HOUR,27,PrevWeekEndTS)
DECLARE @entries TABLE (ID INT IDENTITY, habitID INT, date DATETIME)
INSERT INTO @entries (habitID, date) VALUES
(1, '20150218'),(1, '20150225'), (2, '20150218')
DECLARE @habits TABLE (habitID INT, habitStartDate DATE, habitEndDate DATE, target INT)
INSERT INTO @habits (habitID, habitStartDate, habitEndDate, target) VALUES
(1, '2015-02-16',NULL,1 ),(2, '2015-02-16',NULL, 1)
IF EXISTS (SELECT 'x' FROM tempdb.sys.tables WHERE name LIKE '#seq%') DROP TABLE #seq
CREATE TABLE #seq (habitID INT, ID INT, today DATE, seq INT, target INT, hits INT, habitStartDate DATE, habitEndDate DATE)
CREATE CLUSTERED INDEX IDXc_HabitID ON #seq (habitID)
INSERT INTO #seq (habitID, ID, today, seq, target, hits, habitStartDate, habitEndDate)
SELECT a.habitID, CASE WHEN COUNT(e.id) >= a.target THEN MAX(e.ID) ELSE NULL END AS ID, a.today, ROW_NUMBER() OVER (PARTITION BY a.habitID ORDER BY a.today) AS seq, a.target, COUNT(e.id) AS hits, habitStartDate, habitEndDate
FROM (
SELECT e.habitID, c.today, e.target, habitStartDate, habitEndDate
FROM @habits e
INNER JOIN calendar c
ON c.today BETWEEN e.habitStartDate AND COALESCE(e.habitEndDate,CURRENT_TIMESTAMP)
GROUP BY habitID, today, e.target, habitStartDate, habitEndDate
) a
LEFT OUTER JOIN @entries e
ON a.habitID = e.habitID
AND DATEADD(SECOND,-10801,e.date) BETWEEN a.today AND DATEADD(SECOND,86459,a.today)
GROUP BY a.habitID, a.today, a.target, habitStartDate, habitEndDate
IF EXISTS (SELECT 'x' FROM tempdb.sys.tables WHERE name LIKE '#base%') DROP TABLE #base
CREATE TABLE #base (habitID INT, habitStartDate DATE, habitEndDate DATE, habitWeekStart DATE, entries INT, seq INT)
CREATE CLUSTERED INDEX IDXc_habitID ON #base (habitID)
CREATE NONCLUSTERED INDEX IDX_habitID_Seq ON #base (habitID, seq) INCLUDE (habitStartDate, habitEndDate, habitWeekStart, entries)
INSERT INTO #base (habitID, habitStartDate, habitEndDate, habitWeekStart, entries, seq)
SELECT h.habitID, h.habitStartDate, h.habitEndDate, c.habitWeekStart, COUNT(e.ID) AS entries, ROW_NUMBER() OVER (PARTITION BY h.habitID ORDER BY c.habitWeekStart) AS seq
FROM @habits h
INNER JOIN calendar c
ON c.today BETWEEN h.habitStartDate AND COALESCE(h.habitEndDate,CURRENT_TIMESTAMP)
LEFT OUTER JOIN @entries e
ON c.today = e.date
AND h.habitID = e.habitID
GROUP BY h.habitID, h.habitStartDate, h.habitEndDate, c.habitWeekStart
;WITH rCTE AS (
SELECT habitID, habitStartDate, habitEndDate, seq, habitWeekStart, entries, CASE WHEN entries > 0 THEN 1 ELSE 0 END as streak
FROM #base
WHERE seq = 1
UNION ALL
SELECT r.habitID, r.habitStartDate, r.habitEndDate, b.seq, b.habitWeekStart, b.entries, CASE WHEN b.entries > 0 THEN r.streak+1
WHEN b.entries = 0 AND r.entries = 0 THEN r.streak-1
ELSE -1 END as streak
FROM rCTE r
INNER JOIN #base b
ON r.habitID = b.habitID
AND r.seq + 1 = b.seq
), rCTEw AS (
SELECT id, habitID, today, seq, CAST(CASE WHEN id IS NULL THEN 0 ELSE 1 END AS INT) AS streak, hits, target, habitStartDate, habitEndDate
FROM #seq
WHERE seq = 1
UNION ALL
SELECT e.id, e.habitID, e.today, e.seq, CAST(CASE WHEN r.ID IS NOT NULL AND e.ID IS NOT NULL THEN r.streak+1
WHEN e.ID IS NULL AND r.ID IS NULL THEN r.streak-1
WHEN e.ID IS NOT NULL AND r.ID IS NULL THEN 1
ELSE 0
END AS INT) AS streak, e.hits, e.target, r.habitStartDate, r.habitEndDate
FROM rCTEw r
INNER JOIN #seq e
ON r.habitID = e.habitID
AND r.seq+1 = e.seq
SELECT habitID, habitStartDate, habitEndDate, today, entries, streak, 'weekly' AS period
FROM rCTE r
INNER JOIN calendar c
ON r.habitWeekStart = c.today
AND c.weekEndTS > DATEADD(DAY,-7,CURRENT_TIMESTAMP)
AND c.weekEndTS < CURRENT_TIMESTAMP
UNION ALL
SELECT habitID, habitStartDate, habitEndDate, today, hits, streak, 'daily'
FROM rCTEw
WHERE today = CAST(DATEADD(DAY,-1,'2015-03-02') AS DATE)
ORDER BY period, habitID, today
and here's the result:
habitID habitStartDate habitEndDate today entries streak period
1 2015-02-16 NULL 2015-03-01 00:00:00.000 0 -4 daily
2 2015-02-16 NULL 2015-03-01 00:00:00.000 0 -11 daily
1 2015-02-16 NULL 2015-02-23 00:00:00.000 1 2 weekly
2 2015-02-16 NULL 2015-02-23 00:00:00.000 0 -1 weekly

Similar Messages

  • Latest Number of Consecutive Days ("Current Streak")

    Using SQL Server (On Azure)
    I am trying to figure out how to get the latest number of consecutive days in an SQL query.
    I have a habit tracking app in which I keep track of best streaks, originally I was storing this "Streak" value as it's own column in the Habit table and changing it directly. This of course led to incorrect syncing and accuracy issues. I realize
    the best way to do it is to calculate from existing data.
    I simplified the 2 tables as listed below:
    Habit
    id (the habit id)
    Name (the name of the habit)
    Target (the target number of entries required to be considered completed)
    HabitEntry
    id (the habit entry id)
    HabitID (the corresponding habit id)
    EntryDate (the date and time of the entry)
    Looking to get a query that looks something like this:
    SELECT habit.id, habit.Name, (*subquery*) as 'CurrentStreak' from habit join habitentry on habit.id = habitentry.habitid
    And outputs something like this:
    1, 'Exercise Daily', 7
    If the habit's target is 2, there must be 2 entries within that date to be considered completed and to add to the streak.
    Not sure if this complicates things, but days are measured from 3:00am to 3:00am, any help is greatly appreciated.

    Figured I'd throw this in just for the fun of it. :)
    IF OBJECT_ID('tempdb..#Habbit') IS NOT NULL DROP TABLE #Habbit
    CREATE TABLE #Habbit (
    ID INT PRIMARY KEY,
    Name VARCHAR(255),
    [Target] INT
    INSERT #Habbit (ID,Name,Target) VALUES
    (1,'Three Day Thing', 3),
    (2,'Four Day Thing', 4),
    (3,'Five Day Thing', 5)
    --=============================================
    IF OBJECT_ID('tempdb..#HabitEntry') IS NOT NULL DROP TABLE #HabitEntry
    CREATE TABLE #HabitEntry (
    UserID INT,
    HabbitID INT,
    EntryDate DATETIME
    INSERT #HabitEntry (UserID,HabbitID,EntryDate) VALUES
    (1, 1, '20150101 06:35:30'),
    (1, 1, '20150102 08:35:30'),
    (1, 1, '20150103 08:35:30'),
    (1, 1, '20150110 09:35:30'),
    (1, 1, '20150112 10:35:30'),
    (1, 1, '20150115 22:35:30'),
    (1, 1, '20150116 23:35:30'),
    (1, 1, '20150117 00:35:30'),
    (1, 1, '20150118 01:35:30'),
    (1, 1, '20150122 04:35:30'),
    (1, 1, '20150124 05:35:30'),
    (1, 1, '20150126 15:35:30'),
    (1, 1, '20150127 10:35:30'),
    (2, 3, '20150101 06:35:30'),
    (2, 3, '20150102 06:35:30'),
    (2, 3, '20150103 02:35:30'),
    (2, 3, '20150104 06:35:30'),
    (2, 3, '20150105 06:35:30'),
    (2, 3, '20150108 06:35:30'),
    (2, 3, '20150110 06:35:30'),
    (2, 3, '20150111 06:35:30'),
    (2, 3, '20150112 06:35:30'),
    (2, 3, '20150113 06:35:30'),
    (2, 3, '20150114 06:35:30'),
    (2, 3, '20150122 06:35:30'),
    (2, 3, '20150123 06:35:30')
    --=============================================
    DECLARE @MinDate DATE, @RangeSize INT
    SELECT @MinDate = DATEADD(dd, -1, MIN(he.EntryDate)) FROM #HabitEntry he
    SELECT @RangeSize = DATEDIFF(dd, @MinDate, MAX(he.EntryDate) + 1) FROM #HabitEntry he
    IF OBJECT_ID('tempdb..#CalRanges') IS NOT NULL DROP TABLE #CalRanges
    SELECT TOP (@RangeSize)
    DATEADD(dd, ROW_NUMBER() OVER (ORDER BY (SELECT NULL)), @MinDate) AS [Date],
    DATEADD(hh, 3, DATEADD(dd, ROW_NUMBER() OVER (ORDER BY (SELECT NULL)), CAST(@MinDate AS DATETIME))) AS BegRange,
    DATEADD(hh, 27, DATEADD(dd, ROW_NUMBER() OVER (ORDER BY (SELECT NULL)), CAST(@MinDate AS DATETIME))) AS EndRange
    INTO #CalRanges
    FROM sys.all_objects ao
    --=============================================
    ;WITH cte AS (
    SELECT
    cr.Date,
    he.UserID,
    he.HabbitID,
    he.EntryDate,
    COALESCE(LAG(CASE WHEN he.EntryDate IS NOT NULL THEN cr.Date END, 1) OVER (PARTITION BY he.UserID, he.HabbitID ORDER BY cr.Date), '19000101') AS PrevDate
    FROM
    #CalRanges cr
    JOIN #HabitEntry he
    ON he.EntryDate BETWEEN cr.BegRange AND cr.EndRange
    --AND he.UserID = 1
    ), cte2 AS (
    SELECT
    c.*,
    CASE WHEN DATEDIFF(dd, c.PrevDate, c.Date) <> 1 THEN ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) END ConseqGroup
    FROM cte c
    WHERE c.Date <> c.PrevDate
    ), cte3 AS (
    SELECT
    c2.*,
    CAST(SUBSTRING(MAX(CAST(c2.Date AS BINARY(4)) + CAST(c2.ConseqGroup AS BINARY(4))) OVER (PARTITION BY c2.UserID, c2.HabbitID ORDER BY c2.Date), 5, 4) AS INT) AS ConseqGroupFill
    FROM cte2 c2
    ), cte4 AS (
    SELECT
    c3.UserID,
    c3.HabbitID,
    h.Name AS HabbitName,
    MIN(c3.EntryDate) AS BegDate,
    MAX(c3.EntryDate) AS EndDate,
    COUNT(*) AS DaysInSeries
    FROM
    cte3 c3
    JOIN #Habbit h
    ON c3.HabbitID = h.ID
    GROUP BY
    c3.UserID,
    c3.HabbitID,
    c3.ConseqGroupFill,
    h.Name
    HAVING
    COUNT(*) >= MAX(h.Target)
    -- SELECT * FROM cte4
    SELECT
    c4.*
    FROM (SELECT DISTINCT he.UserID, he.HabbitID FROM #HabitEntry he) AS a
    CROSS APPLY (
    SELECT TOP 1
    FROM cte4 c4
    WHERE a.UserID = c4.UserID
    AND a.HabbitID = c4.HabbitID
    ORDER BY c4.BegDate DESC
    ) c4
    HTH,
    Jason
    Jason Long

  • Get number of month, week and date between 2 dates

    Hi all,
    Is it possible to display number of month, week and days between 2 dates? either by using only SQL query or through PL/SQL...
    Input:
    From date: 01-Oct-2010
    To date: 19-Oct-2010
    I want output as below (Assuming the week starts from Monday to Sunday in oracle).
    01-Oct-2010 -- (Since this is in mid of the week)
    02-Oct-2010 -- (Since this is in mid of the week)
    03-Oct-2010 -- (Since this is in mid of the week)
    40 -- (Oct 4 to Oct 10 falls in 40th week of the year)
    41 -- (Oct 11 to Oct 17 falls in 41th week of the year)
    18-Oct-2010 -- (Since this is in mid of the week)
    19-Oct-2010 -- (Since this is in mid of the week)
    Note: If there is one full month between the given date, then the month number should be displayed.
    After the month, the remaining date comprised with one full week, then the week number of the year should
    be displayed. After displaying the week, the remaining dates should be displayed as it is..
    Appreciate your help..
    Thanks.
    Rajan.

    I suppose if it's just like a calendar type information you want then something like...
    SQL> break on month skip 1
    SQL> set linesize 200
    SQL> set pagesize 2000
    SQL> column month format a20
    SQL> column week format a4
    SQL> with req as (select '&Required_Year_YYYY' as yr from dual)
      2      ,offset as (select case when to_char(trunc(to_date(yr,'YYYY'),'YYYY'),'IW') in ('52','53') then 1 else 0 end as offset from req
      3  select lpad( Month, 20-(20-length(month))/2 ) month,
      4         '('||week||')' as week, "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"
      5  from (
      6    select to_char(dt,'fmMonth YYYY') month,
      7    case when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 0 then '53'
      8         when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 1 then '54'
      9         when to_char(dt, 'mm') = '01' and to_char(dt,'iw') in ('52','53') then '1'
    10         else to_char(to_number(to_char(dt,'iw'))+offset) end as week,
    11    max(decode(to_char(dt,'d'),'1',lpad(to_char(dt,'fmdd'),2))) "Mo",
    12    max(decode(to_char(dt,'d'),'2',lpad(to_char(dt,'fmdd'),2))) "Tu",
    13    max(decode(to_char(dt,'d'),'3',lpad(to_char(dt,'fmdd'),2))) "We",
    14    max(decode(to_char(dt,'d'),'4',lpad(to_char(dt,'fmdd'),2))) "Th",
    15    max(decode(to_char(dt,'d'),'5',lpad(to_char(dt,'fmdd'),2))) "Fr",
    16    max(decode(to_char(dt,'d'),'6',lpad(to_char(dt,'fmdd'),2))) "Sa",
    17    max(decode(to_char(dt,'d'),'7',lpad(to_char(dt,'fmdd'),2))) "Su"
    18    from ( select trunc(to_date(req.yr,'YYYY'),'y')-1+rownum dt
    19           from all_objects, req
    20           where rownum <= add_months(trunc(to_date(req.yr,'YYYY'),'y'),12) - trunc(to_date(req.yr,'YYYY'),'y') )
    21        ,offset
    22    group by to_char(dt,'fmMonth YYYY'),     case when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 0 then '53'
    23                                                  when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 1 then '54'
    24                                                  when to_char(dt, 'mm') = '01' and to_char(dt,'iw') in ('52','53') then '1'
    25                                                  else to_char(to_number(to_char(dt,'iw'))+offset) end
    26    ) x
    27  order by to_date( month, 'Month YYYY' ), to_number(x.week)
    28  /
    Enter value for required_year_yyyy: 2010
    old   1: with req as (select '&Required_Year_YYYY' as yr from dual)
    new   1: with req as (select '2010' as yr from dual)
    MONTH                WEEK Mo Tu We Th Fr Sa Su
        January 2010     (1)               1  2  3
                         (2)   4  5  6  7  8  9 10
                         (3)  11 12 13 14 15 16 17
                         (4)  18 19 20 21 22 23 24
                         (5)  25 26 27 28 29 30 31
       February 2010     (6)   1  2  3  4  5  6  7
                         (7)   8  9 10 11 12 13 14
                         (8)  15 16 17 18 19 20 21
                         (9)  22 23 24 25 26 27 28
         March 2010      (10)  1  2  3  4  5  6  7
                         (11)  8  9 10 11 12 13 14
                         (12) 15 16 17 18 19 20 21
                         (13) 22 23 24 25 26 27 28
                         (14) 29 30 31
         April 2010      (14)           1  2  3  4
                         (15)  5  6  7  8  9 10 11
                         (16) 12 13 14 15 16 17 18
                         (17) 19 20 21 22 23 24 25
                         (18) 26 27 28 29 30
          May 2010       (18)                 1  2
                         (19)  3  4  5  6  7  8  9
                         (20) 10 11 12 13 14 15 16
                         (21) 17 18 19 20 21 22 23
                         (22) 24 25 26 27 28 29 30
                         (23) 31
         June 2010       (23)     1  2  3  4  5  6
                         (24)  7  8  9 10 11 12 13
                         (25) 14 15 16 17 18 19 20
                         (26) 21 22 23 24 25 26 27
                         (27) 28 29 30
         July 2010       (27)           1  2  3  4
                         (28)  5  6  7  8  9 10 11
                         (29) 12 13 14 15 16 17 18
                         (30) 19 20 21 22 23 24 25
                         (31) 26 27 28 29 30 31
        August 2010      (31)                    1
                         (32)  2  3  4  5  6  7  8
                         (33)  9 10 11 12 13 14 15
                         (34) 16 17 18 19 20 21 22
                         (35) 23 24 25 26 27 28 29
                         (36) 30 31
       September 2010    (36)        1  2  3  4  5
                         (37)  6  7  8  9 10 11 12
                         (38) 13 14 15 16 17 18 19
                         (39) 20 21 22 23 24 25 26
                         (40) 27 28 29 30
        October 2010     (40)              1  2  3
                         (41)  4  5  6  7  8  9 10
                         (42) 11 12 13 14 15 16 17
                         (43) 18 19 20 21 22 23 24
                         (44) 25 26 27 28 29 30 31
       November 2010     (45)  1  2  3  4  5  6  7
                         (46)  8  9 10 11 12 13 14
                         (47) 15 16 17 18 19 20 21
                         (48) 22 23 24 25 26 27 28
                         (49) 29 30
       December 2010     (49)        1  2  3  4  5
                         (50)  6  7  8  9 10 11 12
                         (51) 13 14 15 16 17 18 19
                         (52) 20 21 22 23 24 25 26
                         (53) 27 28 29 30 31
    61 rows selected.
    SQL>

  • Number of the week in Ical

    Howcome the number of the week isn´t shown in Ical????

    there's no option for a week view in iCal, but John Maisey wrote this applescript.
    paste it in the Script Editor (Applications --> AppleScript --> Script Editor) and run it once...
    if your weekview starts on an other day change this line:
    set daysText to "MonTueWedThuFriSatSun"
    to (example)
    set daysText to "SunMonTueWedThuFriSat"
    --Copy below this line into Script Editor and click run --
    --Annual Week numbers
    --John Maisey
    --4/2/5
    set numberOfWeeks to 1000 -- change as needed
    set daysText to "MonTueWedThuFriSatSun"
    set aDate to (current date)
    set day of aDate to 1
    set month of aDate to January
    set aDay to weekday of aDate
    set weekNo to 1
    --Day of week as num. starting with 0
    set aDayText to (characters 1 thru 3 of (aDay as text)) as text
    set dayOff to ((offset of aDayText in daysText) - 1) / 3 as integer
    if dayOff is less than 5 then
    set StartDate to aDate - dayOff * days
    else
    set StartDate to aDate + (7 - dayOff) * days
    end if
    tell application "iCal"
    set newCal to make new calendar at end of calendars with properties {title:"Week No."}
    set myCal to (count of every calendar)
    end tell
    repeat with myCount from 1 to numberOfWeeks
    if (month of StartDate is December) and (day of StartDate is greater than 28) then set weekNo to 1
    if (month of StartDate is January) and (day of StartDate is less than 5) then set weekNo to 1
    set weekText to "Week No. " & weekNo
    tell application "iCal"
    tell calendar myCal
    make new event at end of events with properties {start date:StartDate, allday event:true, summary:weekText}
    end tell
    end tell
    set weekNo to weekNo + 1
    set StartDate to StartDate + 7 * days
    end repeat
    --

  • Date - how to get the number of the week

    I have a Date - string - w/e can be convered thats not the problem
    but how do I get the number of the week cuz the database holds events per week so I need to know the number of the week.
    I tried going true the api but I failed to find the right fuction, aldoh I recall seeing it somewhere a while ago.
    anyways got a deathline so easy dukies, first come first serve.

    how's this then?int weekOfYear = 0;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); //your String format
    Date date = null;
    String dateString = "2003/06/16";
    try {
      date = sdf.parse(dateString);
    } catch (ParseException pe) {
      //hande bad date format
    if (date != null) {
      GregorianCalendar calendar = new GregorianCalendar();
      calendar.setTime(date);
      weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR);
    Warning: Be careful of your locale settings when using week of year, you may need to investigate setFirstDayOfWeek(int value) and setMinimalDaysInFirstWeek(int value) to ensure you get the results you expect.

  • Number of current week

    How do I get the number of current week?

    select to_char(sysdate,'W') AS "WEEK OF THE YEAR" from dual (wk of the month)
    select to_char(sysdate,'WW') AS "WEEK OF THE YEAR" from dual (wk of the year)

  • FM to find the number of fiscal weeks in a year

    Hi All,
    Can anyone pls give me the  function module to find the number of fiscal weeks in the given year.
    Thanks,
    Rajani.

    Eric Cartman wrote:
    Ámit Güjärgoüd wrote:
    > > Eric,
    > >
    > > Did you actually enjoy 2004 ?
    wasn't bad...
    do you mean, there were 53 weeks in that year? because I have concern, how it is actually counted...
    wasn't bad... :)
    Thats sounds Sweet
    do you mean, there were 53 weeks in that year?
    Yes
    because I have concern, how it is actually counted...
    If in a leap year fabruary falls in 5 weeks then that is the only possibility for 53 weeks
    Cheers
    PS:But No logic would be applied in this case

  • How to know the number of the week in iCal ?

    Hi !
    I'm very enjoying iCal. But, there is something very important for me that I can't find in iCal !
    I need to know the number of the week (in Month, Week or Day views).
    Is that a way to easily see it ?
    Regards,
    ant
    iMac G5   Mac OS X (10.4.2)  

    there's no option for a week view in iCal, but John Maisey wrote this applescript.
    paste it in the Script Editor (Applications --> AppleScript --> Script Editor) and run it once...
    if your weekview starts on an other day change this line:
    set daysText to "MonTueWedThuFriSatSun"
    to (example)
    set daysText to "SunMonTueWedThuFriSat"
    --Copy below this line into Script Editor and click run --
    --Annual Week numbers
    --John Maisey
    --4/2/5
    set numberOfWeeks to 1000 -- change as needed
    set daysText to "MonTueWedThuFriSatSun"
    set aDate to (current date)
    set day of aDate to 1
    set month of aDate to January
    set aDay to weekday of aDate
    set weekNo to 1
    --Day of week as num. starting with 0
    set aDayText to (characters 1 thru 3 of (aDay as text)) as text
    set dayOff to ((offset of aDayText in daysText) - 1) / 3 as integer
    if dayOff is less than 5 then
    set StartDate to aDate - dayOff * days
    else
    set StartDate to aDate + (7 - dayOff) * days
    end if
    tell application "iCal"
    set newCal to make new calendar at end of calendars with properties {title:"Week No."}
    set myCal to (count of every calendar)
    end tell
    repeat with myCount from 1 to numberOfWeeks
    if (month of StartDate is December) and (day of StartDate is greater than 28) then set weekNo to 1
    if (month of StartDate is January) and (day of StartDate is less than 5) then set weekNo to 1
    set weekText to "Week No. " & weekNo
    tell application "iCal"
    tell calendar myCal
    make new event at end of events with properties {start date:StartDate, allday event:true, summary:weekText}
    end tell
    end tell
    set weekNo to weekNo + 1
    set StartDate to StartDate + 7 * days
    end repeat
    --

  • Show number of a week in a month

    Dear all,
    I want to know a number of the week in a month of my transaction.
    The table has a field called transaction_date. How to write a sql which will show a number of week (1, 2, 3 or 4) in that very month where the transaction was made.
    Thanks and regards,
    Steve

    Hi Steve,
    I don't know if you know about it but there is a forum dedicated to PL / SQL which might be better for this type of question. In any case , browsing the SQL documentation at the moment there is a date time format W which appears to do what you want. There are in fact two week number formats WW and W. One is for week number in the year the other for week number in the month. Hope this helps. Here is a link:
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96529/ch7.htm#5186

  • How do I number pages consecutively starting with a number other than 1?

    In Pages, how do I number pages consecutively starting with a number other than 1?

    Inspector > Document > Section > Page Numbering:     click on the dropdown menu

  • Extract arrays according the number of consecutive values

    Hello I would need some help on one problem to search the
    number of consecutive values in an array. I am using Labview 8.1
    First I have a 2D array with 3 columns: Col (A)  Col (B) 
    Col (C). I would like to plot points from Col( B)=f(ColC) at Constant
    value in Column A. The problem is that in Column A the values changes. My
    problem is to extract arrays when the values in column A are the same and when
    the number of values is higher than a number that I can choose. In my case I
    chosse this number by the threshold function on the peak detector.
    Let ‘s take an exemple:
    Col (A)            Col(B)              Col(
    C)
    12                    343                  45
    654                  65                    33                               
    121                  65                    65                   
    18                    31                    45                   
    12                    456                  98       
    787                  361                  787
    121                  156                  123     
    12                    32                    545
    Let ‘s say I want to plot Col(B)=f( Col(C)) at constant value in
    Column A when I have more than 2 constant values in Column A
    The aim would be to have different arrays to plot 2
    different graphs for different constant value in Col( A).
    Col (A)            Col
    (B) Col( C)                        Col (A)            Col(B)              Col(C)
    12                    343                  45                       121                  65                    65       
    12                    456                  98           &          121                  156                  123
    12                    32                    545
     What I do with the VI is:
    1)      sort
     the 2D arrays accordind the values in
    the Col (A) and extract Col(A)
    2)      Search
    the index of elements in Column A when they I do not have consecutive values
    3)      Subtract
    each new indexes indexes 2 by 2: this gives me the number of consecutive values
    in a new array.
    4)      Detect
    the indexes of the peak (number of consecutive values) that I want (in the
    exemple= 2)
    My problem is now to come back in
    the initial array and extract the arrays that has more than n  consecutive values
    (n=2 in the exemple) according to the index found by the peak values.
     I am sure that there is a simpler
    and better way to do this (maybe by a for loop or by using an histogram);
    Thank in advance for the help
    Olivier
    Attachments:
    extract values.vi ‏33 KB

    First, I wanted to thank you, Kumar for the quick answer: 5
    stars for the answer, this is exactly what I was looking for. I would not have
    found it by myself.
    I have an other problem to plot now Col( B)=f (Col( C))
    What I would like to do is plot Col (B)=Col (C) with
    different plots (colour) on a same graph when the value in column A changes.
    I managed to have 2 arrays (thanks to the forum with some
    modifications):
    -One to tell me each first indexes when the value changes
    -One to tell me each last indexes when the values changes
    My idea would be to use theses indexes to split the initial
    array by  a loop when the value in Column
    A changes and then in an other loop  (or
    in the same) connect the XY graph to the build arrays.
    The only problem is that before running Labview I do not
    know how many different values in column A I have so I do not know how many
    arrays will be created when I will try to split the initial array.
    Is someone know if this solution is possible?
    Thank you in advance for the help.
    Olivier

  • Oracle reverse date : inupt (number of the week, number of the date, year)

    Hi experts,
    *I have a date that has been stored in three separated columns in a oracle data base 10g:
    -number of week: for example 30. (range 1-53)
    -number of the day: for example 5. (range 1-7).
    -year : for example 2010.
    *i need to write a SQL code which concate and convert this three columns to one signle date in the format dd/mm/yyyy.
    *This a concrete example:
    -input:
    number of the day: 2, number of the week :23, year 2010.
    -ouput:
    07/06/2010
    Any idea will be welcome
    Best regards.

    Hi,
    Here's one way :
    alter session set nls_date_language = "english";
    alter session set nls_territory = "america";
    WITH date_parts AS (
    select 2010 yr, 23 wk, 2 dy from dual union all
    select 2010 yr, 39 wk, 2 dy from dual
    SELECT next_day(to_date('0101'||yr,'DDMMYYYY')-7, 'SUN') - 1
           + 7*wk
           + dy
           AS dt
    FROM date_parts;You might have to make some adjustments due to your nls settings.

  • My Mac laptop was running fine till I downloaded the latest itunes version this week, now all the programs are slow, ITUNEs cuts in and out.  Anyone know what I did wrong?

    My Mac laptop was running fine till I downloaded the latest itunes version this week, now all the programs are slow, ITUNEs cuts in and out.  Anyone know what I did wrong?

    Hello Mark Malecki,
    Thanks for the question, and welcome to Apple Support Communities.
    I understand you are having some issues with iTunes on your MacBook. You may want to isolate the issues further by testing to see if they persist in a new user account:
    Isolating an issue by using another user account
    http://support.apple.com/kb/TS4053
    You can also try starting iTunes in safe mode:
    iTunes: Troubleshooting issues with third-party iTunes plug-ins
    http://support.apple.com/kb/TS3430
    Thanks,
    Matt M.

  • IPhone 5c has lost its color. Everything on screen is gray.  I have already checked "grayscale". Button is not "on".  I downloaded latest software about a week ago but today is when color changed. Any help?

    iPhone 5c has lost its color. Everything on screen is gray.  I have already checked "grayscale". Button is not "on".  I downloaded latest software about a week ago but today is when color changed. Any help?

    Hi ..
    Try a reset.
    Press and hold the Sleep/Wake button and the Home button together for at least ten seconds, until the Apple logo appears.

  • Calendar week: how to substract a number of calendar weeks from a given one

    Hi Experts,
    Is there a way to calculate this:
    If my calendar week is 01.2009 and I want to calculate the corresponding week 18 weeks ago, is there a FM that calculates this?
    I tried 01.2009 - 18 but is giving me the wrong week.
    Thanks in advance.
    Inma

    DATA : GV_MONDAY TYPE D,
           GV_DATES  TYPE I,
           GV_WEEK   TYPE KWEEK.
    PARAMETERS: P_WEEK  TYPE KWEEK DEFAULT '200901',
                P_WEEKS TYPE I.
    START-OF-SELECTION.
      CALL FUNCTION 'WEEK_GET_FIRST_DAY'
        EXPORTING
          WEEK         = P_WEEK
        IMPORTING
          DATE         = GV_MONDAY
        EXCEPTIONS
          WEEK_INVALID = 1
          OTHERS       = 2.
      IF SY-SUBRC  0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      GV_DATES = P_WEEKS * 7.
      GV_MONDAY = GV_MONDAY - GV_DATES.
      CALL FUNCTION 'DATE_GET_WEEK'
        EXPORTING
          DATE              = GV_MONDAY
       IMPORTING
         WEEK               = GV_WEEK
       EXCEPTIONS
         DATE_INVALID       = 1
         OTHERS             = 2
      IF SY-SUBRC  0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      WRITE :/ P_WEEK, '-', P_WEEKS , ': =', GV_WEEK.
    Regards,
    Shafivullah Mohammad
    Edited by: shafivullah mohammad on Jul 9, 2009 12:44 PM

Maybe you are looking for

  • Strange issue in Report Builder

    Hi All, I am facing a strange issue in Report Builder. I am having a report which is currently in production. when i am opening that report and just saving it without making any changes, then also the size of the report is reducing from 238 to 204 kb

  • Combining columns of multiple files in one file

    I have several hundred text files that contain a lot of information. Each file has 3 columns (the first two are the same for all the files). I need to merge the third column of all the files in a new file. And insert a column header with the name of

  • How to make the font shown in Flash CS5 ?

    The font can not be shown in Flash CS5, I download the Meiryo font from internet, and paste it to the font folder in windows7 control panel , when i re-open the flash cs5, it is not shown yet. who can tell me how to solve this problem?

  • PDFMaker issue with Excel

    I'm experiencing an issue with PDFMaker when converting an Excel 2003 document.  I have an image that is in the header of the Excel document.  When I print in Excel it looks fine, but when I covert it to PDF it is much smaller.  This seems to only ha

  • A few questions about mail

    I'm new to mail and OSX so please be kind if I am being stupid.. I use Mail with my Exchange 2007 account, is Mail able to do the following as I cannot find it anywhere.. 1. Unmark junk set by Exchange and add to trust list on the server., then move