SELECT 
    '## '||(SELECT (SELECT MAX(mdate) FROM rlarp.thirtysec)::date - ((EXTRACT(DOW FROM (SELECT MAX(mdate) FROM rlarp.thirtysec)::date) - 5 + 7) % 7) * INTERVAL '1 day' AS last_friday) 
    UNION ALL 
    SELECT '- ' ||mdate||' [[]] '||(message->>'text') 
FROM 
    rlarp.thirtysec 
WHERE 
    mdate >= (SELECT (SELECT MAX(mdate) FROM rlarp.thirtysec)::date - ((EXTRACT(DOW FROM (SELECT MAX(mdate) FROM rlarp.thirtysec)::date) - 5 + 7) % 7) * INTERVAL '1 day' AS last_friday)
