My SQLite cte exercise, the output looks like cal in Linux shell:
------
with recursive
  parameters(aday) as (
   select date()
  ),
  months(n, nm) as (
  
values(1,'January'),(2,'February'),(3,'March'),(4,'April'),(5,'May'),(6,'June'),
   
(7,'July'),(8,'August'),(9,'September'),(10,'October'),(11,'November'),(12,'December')
  ),
  daystr(s) as (
     select substr('              ', 1, strftime('%w',aday,'start of 
month')*3-1 ) ||
       substr('  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
22 23 24 25 26 27 28 29 30 31',
            1, strftime('%d',aday,'start of month','+1 month','-1 day')*3)
     from parameters
  ),
  padstr(i,s,r) as (
     select 0,'', s from daystr union all select i+1, substr(r, 1, 
7*3-1),substr(r,7*3+1)
     from padstr where r <>''
  ),
  monthTitle(mt) as (
    select nm || ' ' || strftime('%Y', aday)
      from months,parameters
      where n = 0 + strftime('%m',aday)
  ),
  cal(s) as (
    select substr('          ',1, (20-length(mt))/2) || mt
      ||char(13,10) ||  'Su Mo Tu We Th Fr Sa' || char(13,10) ||
      group_concat(s,char(13,10)) from padstr,monthTitle where s <>''
  )
select * from cal;

----
   February 2016
Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6
7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10

From: Stephan Beal<mailto:sgb...@googlemail.com>
Sent: 2016?2?19? 9:00
To: SQLite mailing list<mailto:sqlite-users at mailinglists.sqlite.org>
Subject: Re: [sqlite] determining is-leap-year in sqlite

On Fri, Feb 19, 2016 at 1:53 AM, Stephan Beal <sgbeal at googlemail.com> wrote:

> It can now optionally mark the current date (but this feature slowed it
> down from 'instant' to 'just under a second or so', possibly due to SQL
> inefficiencies on my part).
>

Trimming the list of years from 100 years to now +/-5 years brought it back
to 'instant'. :) The latest code is online.

--
----- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
"Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do." -- Bigby Wolf
_______________________________________________
sqlite-users mailing list
sqlite-users at mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to