in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

Select year data from a DateTime field

Last post 09-25-2007 8:37 AM by Robert Simpson. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 09-06-2007 5:16 AM

    Select year data from a DateTime field

    Hello,

    I have a datetime field (mydate) in my table (mytable), and I want to get all different year from this table.

    Here is the query which works in MySQL :

    string queryString = "Select distinct year(mydate) as year from mytable"

    I want to make the same query using SQLite

    I have try this :

    string queryString = @"Select distinct strftime(""%Y"", mydate) as year from mytable"

    But the result is always an empty string.

    This following exemple works :

     string queryString = @"Select distinct strftime(""%Y"", 'now') as year"  --> return "2007"

     string queryString = @"Select distinct strftime(""%Y"", '2001-01-01 19:05:04'') as year"  --> return "2001"

    I think, my problem is to specify correctly the field 'mydate'. I have tried :

    - mydate 

    - 'mydate' 

    - [mydate]

    without success.

    What is wrong ?

    Is there a other way to make this query ? 

    Thanks in advance

    Olivier 

     

    Filed under: , ,
  • 09-25-2007 8:37 AM In reply to

    Re: Select year data from a DateTime field

    Not really sure what's going wrong without looking at your database.  How are the dates in your database formatted?  If they don't use ISO8601 formatting, then the strftime() function won't work properly.

    Robert

     

Page 1 of 1 (2 items)
Powered by Community Server (Commercial Edition), by Telligent Systems