strftime() issues

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

strftime() issues

Roy Sigurd Karlsbakk
Hi all

Trying to use strftime() to extract current Year-Month seems to go nuts. Any ideas?

$ sqlite3
SQLite version 3.6.20
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select strftime('%s', 'now');
1413536061
sqlite> -- fine, but
sqlite> select strftime('%Y-%m', strftime('%s', 'now'));
3865-46
sqlite> -- ?!??
sqlite> .quit
$

--
Vennlige hilsener / Best regards

roy
--
Roy Sigurd Karlsbakk
(+47) 98013356
[hidden email]
http://blogg.karlsbakk.net/
GPG Public key: http://karlsbakk.net/roysigurdkarlsbakk.pubkey.txt
--
I all pedagogikk er det essensielt at pensum presenteres intelligibelt. Det er et elementært imperativ for alle pedagoger å unngå eksessiv anvendelse av idiomer med xenotyp etymologi. I de fleste tilfeller eksisterer adekvate og relevante synonymer på norsk.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: strftime() issues

Clemens Ladisch
Roy Sigurd Karlsbakk wrote:
> Trying to use strftime() to extract current Year-Month seems to go nuts.
>
> sqlite> select strftime('%s', 'now');
> 1413536061
> sqlite> select strftime('%Y-%m', strftime('%s', 'now'));
> 3865-46

SQLite interprets a number as a Julian day number.  To have it
interpreted as second requires the "unixepoch" modifier:

  sqlite> select strftime('%Y-%m', strftime('%s', 'now'), 'unixepoch');
  2014-10

Anyway, there's no reason to call strftime() twice:

  sqlite> select strftime('%Y-%m', 'now');
  2014-10


Regards,
Clemens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users