Difference between revisions of "SQLite - Select Date for a specific month - Extract month from a date to check that in a where clause"

 
Line 1: Line 1:
 
Use strftime() - Here as an example all dates with the month July (number 7) are selected.
 
Use strftime() - Here as an example all dates with the month July (number 7) are selected.
  
<pre>SELECT * FROM tablename WHERE strftime('%m', date_column) = '07'</pre>
+
<pre>SELECT * FROM tablename WHERE strftime('%m', datecolumn) = '07'</pre>
 
+
tablename is your table name and datecolumn is your column where your date is saved.
 
<br>
 
<br>
 
<br>
 
<br>

Latest revision as of 15:16, 6 October 2019

Use strftime() - Here as an example all dates with the month July (number 7) are selected.

SELECT * FROM tablename WHERE strftime('%m', datecolumn) = '07'

tablename is your table name and datecolumn is your column where your date is saved.

If you want to extract the Month for the current date, then use the following SQL query:

SELECT strftime('%m','now')


More about strftime()
https://www.w3resource.com/sqlite/sqlite-strftime.php