Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting rows where datetime column is a certain day

I'm trying to write a SQLite query in Android where I select all rows from a table where the day component of the datetime column (stored as ISO 8601 strings) equals a given day. Basically, I want to select all rows with a certain date, disregarding the time.

How can this be achieved?

like image 951
Tyler Treat Avatar asked Nov 30 '25 21:11

Tyler Treat


1 Answers

Use this query

select * from table_name where day=desired_day;

So this code:

database.query("table_name", null, "day like ?",new String[]{"____-__-daynumber%"}, null, null, null, null); 

Checkout this documentation to see how I figured out that sql regex to use. This regex allows for any year and any month. If you want only a specific day in a specific month in a specific year do:

database.query("table_name", null, "day like ?",new String[]{"1983-03-22%"}, null, null, null, null); 

This would look for the day 03/22/1983

like image 112
Kurtis Nusbaum Avatar answered Dec 03 '25 10:12

Kurtis Nusbaum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!