Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite SELECT date for a specific month

I was using Microsoft's Jet database engine before. And, say, if I needed to select entries for a specific month I do this:

SELECT * FROM `table name` WHERE MONTH(`date column`)=4

But how do you do the same with SQLite?

like image 984
ahmd0 Avatar asked Apr 14 '11 20:04

ahmd0


People also ask

How do I display the start date of the month in SQLite?

SELECT date('now','start of month','+13 month','-1 day') as "Last Date of current month after a Year"; Here is the result. Example-6: If you want to get the last date of the current month after 4 years, the following SQL statements can be used.

How do I create a date field in SQLite?

First, create a new table named datetime_real . Second, insert the “current” date and time value into the datetime_real table. We used the julianday() function to convert the current date and time to the Julian Day. Third, query data from the datetime_real table.

What is the use of date () function in SQLite?

The date() function returns the date as text in this format: YYYY-MM-DD. The time() function returns the time as text in this format: HH:MM:SS. The datetime() function returns the date and time as text in their same formats: YYYY-MM-DD HH:MM:SS.

How does SQLite handle dates?

The SQLite date() function is used to calculate the date and return it in the format 'YYYY-MM-DD'. The SQLite datetime() function is used to calculate a date/time value, and return it in the format 'YYYY-MM-DD HH:MM:SS'. The SQLite julianday() function returns the date according to julian day.


2 Answers

How about

SELECT * FROM table_name WHERE strftime('%m', date_column) = '04'

Date And Time Functions

like image 115
ikegami Avatar answered Oct 27 '22 19:10

ikegami


SELECT * FROM `table name` WHERE strftime('%m', `date column`) = '04'

sqlite date&time functions

like image 45
manji Avatar answered Oct 27 '22 19:10

manji