Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to structure my query in sqlite?

I would like to retrieve today's data. At the moment I have something like SELECT * FROM myTable WHERE timeStamp>DATETIME('NOW','-1 DAY') but this gives me results from now to 24hrs back, not just today (i.e. no matter how many hours have passed since 00:00). Using the same logic I want to retrieve data for just yesterday, and for the this week.

[EDIT] By the term this week i mean.. if today is Thursday, i want to show results from monday or Sunday (it doesnt matter) upto now.

like image 772
JustCurious Avatar asked Oct 14 '25 09:10

JustCurious


1 Answers

Instead of timeStamp > DATETIME('now') use timeStamp >= DATE('now').

For since yesterday you can use DATE('now', '-1 day').

As for this week - it depends if you mean 7 days ago:

DATE('now', '-7 days')

Or if you mean since the beginning of the first day of this week:

DATE('now', 'weekday 0', '-7 days')
like image 56
PinnyM Avatar answered Oct 18 '25 03:10

PinnyM



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!