How to select sales from 12PM today to next day 5AM in sqlite
up vote
1
down vote
favorite
I have a requirement to select the daily sales from Present Day 12PM to Next Day 5AM is there any way to do this.
Example: 2018-11-08 12:00
To 2018-11-09 05:00
(when initiated on 2018-11-08)
I am able to retrieve daily sales before 23:59
but unable to do get the next day's sales up to 05:00.
I have Orders
table that have Order_date
datatype is TEXT
and datetime format is YYYY-MM-DD HH:mm
sqlite
New contributor
add a comment |
up vote
1
down vote
favorite
I have a requirement to select the daily sales from Present Day 12PM to Next Day 5AM is there any way to do this.
Example: 2018-11-08 12:00
To 2018-11-09 05:00
(when initiated on 2018-11-08)
I am able to retrieve daily sales before 23:59
but unable to do get the next day's sales up to 05:00.
I have Orders
table that have Order_date
datatype is TEXT
and datetime format is YYYY-MM-DD HH:mm
sqlite
New contributor
@vizsatiz sqlite doesn't have a "datetime" type. If OP is storing timestamps as strings,TEXT
is the appropriate type. (Personally, I'd use the unix time in anINTEGER
affinity column instead)
– Shawn
21 hours ago
Show what you've tried already in your query.
– Shawn
21 hours ago
@vizsatiz sqlite doesn't support datetime and i have seen the best datatype isTEXT
for storing datetime in sqlite.
– Beeman
21 hours ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a requirement to select the daily sales from Present Day 12PM to Next Day 5AM is there any way to do this.
Example: 2018-11-08 12:00
To 2018-11-09 05:00
(when initiated on 2018-11-08)
I am able to retrieve daily sales before 23:59
but unable to do get the next day's sales up to 05:00.
I have Orders
table that have Order_date
datatype is TEXT
and datetime format is YYYY-MM-DD HH:mm
sqlite
New contributor
I have a requirement to select the daily sales from Present Day 12PM to Next Day 5AM is there any way to do this.
Example: 2018-11-08 12:00
To 2018-11-09 05:00
(when initiated on 2018-11-08)
I am able to retrieve daily sales before 23:59
but unable to do get the next day's sales up to 05:00.
I have Orders
table that have Order_date
datatype is TEXT
and datetime format is YYYY-MM-DD HH:mm
sqlite
sqlite
New contributor
New contributor
edited 18 hours ago
MikeT
12.9k102440
12.9k102440
New contributor
asked 22 hours ago
Beeman
82
82
New contributor
New contributor
@vizsatiz sqlite doesn't have a "datetime" type. If OP is storing timestamps as strings,TEXT
is the appropriate type. (Personally, I'd use the unix time in anINTEGER
affinity column instead)
– Shawn
21 hours ago
Show what you've tried already in your query.
– Shawn
21 hours ago
@vizsatiz sqlite doesn't support datetime and i have seen the best datatype isTEXT
for storing datetime in sqlite.
– Beeman
21 hours ago
add a comment |
@vizsatiz sqlite doesn't have a "datetime" type. If OP is storing timestamps as strings,TEXT
is the appropriate type. (Personally, I'd use the unix time in anINTEGER
affinity column instead)
– Shawn
21 hours ago
Show what you've tried already in your query.
– Shawn
21 hours ago
@vizsatiz sqlite doesn't support datetime and i have seen the best datatype isTEXT
for storing datetime in sqlite.
– Beeman
21 hours ago
@vizsatiz sqlite doesn't have a "datetime" type. If OP is storing timestamps as strings,
TEXT
is the appropriate type. (Personally, I'd use the unix time in an INTEGER
affinity column instead)– Shawn
21 hours ago
@vizsatiz sqlite doesn't have a "datetime" type. If OP is storing timestamps as strings,
TEXT
is the appropriate type. (Personally, I'd use the unix time in an INTEGER
affinity column instead)– Shawn
21 hours ago
Show what you've tried already in your query.
– Shawn
21 hours ago
Show what you've tried already in your query.
– Shawn
21 hours ago
@vizsatiz sqlite doesn't support datetime and i have seen the best datatype is
TEXT
for storing datetime in sqlite.– Beeman
21 hours ago
@vizsatiz sqlite doesn't support datetime and i have seen the best datatype is
TEXT
for storing datetime in sqlite.– Beeman
21 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
I believe the following could be used :-
SELECT * FROM orders
WHERE order_date
BETWEEN (strftime('%Y-%m-%d','now')||' 12:00')
AND (strftime('%Y-%m-%d','now','+1 days')||' 05:00')
;
Working Example
DROP TABLE IF EXISTS orders;
CREATE TABLE IF NOT EXISTS orders (order_date TEXT);
INSERT INTO orders (order_date) VALUES
(strftime('%Y-%m-%d','now','-1 days')||' 11:59'), -- before
(strftime('%Y-%m-%d','now')||' 00:00'), -- before
(strftime('%Y-%m-%d','now')||' 11:59'), -- before (just)
(strftime('%Y-%m-%d','now')||' 12:00'), --*** included
(strftime('%Y-%m-%d','now')||' 23:59'), --*** included
(strftime('%Y-%m-%d','now','+1 days')||' 05:00'), --**** included
(strftime('%Y-%m-%d','now','+1 days')||' 05:01') -- after (just)
;
SELECT * FROM orders
WHERE order_date
BETWEEN (strftime('%Y-%m-%d','now')||' 12:00')
AND (strftime('%Y-%m-%d','now','+1 days')||' 05:00')
;
- Those marked with *** are rows (3 of them) that should be selected.
I want to start current day from noon 12PM so i will change00:00
to12:00
right?
– Beeman
20 hours ago
i don't have AM or PM myOrder_Date
format isYYYY-MM-DD HH:mm
example2018-11-08 14:00
– Beeman
20 hours ago
@Beeman yep sorry missed 12PM. However the AM/PM makes things a little more difficult (need to add 12 hours for PM). Working on that now.
– MikeT
20 hours ago
@Beeman in the example you included. However, makes life easier to not have so won't change (might edit your post to remove AM PM so as not to confuse.)
– MikeT
20 hours ago
@Beeman answer edited accordingly for 12:00
– MikeT
20 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
I believe the following could be used :-
SELECT * FROM orders
WHERE order_date
BETWEEN (strftime('%Y-%m-%d','now')||' 12:00')
AND (strftime('%Y-%m-%d','now','+1 days')||' 05:00')
;
Working Example
DROP TABLE IF EXISTS orders;
CREATE TABLE IF NOT EXISTS orders (order_date TEXT);
INSERT INTO orders (order_date) VALUES
(strftime('%Y-%m-%d','now','-1 days')||' 11:59'), -- before
(strftime('%Y-%m-%d','now')||' 00:00'), -- before
(strftime('%Y-%m-%d','now')||' 11:59'), -- before (just)
(strftime('%Y-%m-%d','now')||' 12:00'), --*** included
(strftime('%Y-%m-%d','now')||' 23:59'), --*** included
(strftime('%Y-%m-%d','now','+1 days')||' 05:00'), --**** included
(strftime('%Y-%m-%d','now','+1 days')||' 05:01') -- after (just)
;
SELECT * FROM orders
WHERE order_date
BETWEEN (strftime('%Y-%m-%d','now')||' 12:00')
AND (strftime('%Y-%m-%d','now','+1 days')||' 05:00')
;
- Those marked with *** are rows (3 of them) that should be selected.
I want to start current day from noon 12PM so i will change00:00
to12:00
right?
– Beeman
20 hours ago
i don't have AM or PM myOrder_Date
format isYYYY-MM-DD HH:mm
example2018-11-08 14:00
– Beeman
20 hours ago
@Beeman yep sorry missed 12PM. However the AM/PM makes things a little more difficult (need to add 12 hours for PM). Working on that now.
– MikeT
20 hours ago
@Beeman in the example you included. However, makes life easier to not have so won't change (might edit your post to remove AM PM so as not to confuse.)
– MikeT
20 hours ago
@Beeman answer edited accordingly for 12:00
– MikeT
20 hours ago
add a comment |
up vote
0
down vote
accepted
I believe the following could be used :-
SELECT * FROM orders
WHERE order_date
BETWEEN (strftime('%Y-%m-%d','now')||' 12:00')
AND (strftime('%Y-%m-%d','now','+1 days')||' 05:00')
;
Working Example
DROP TABLE IF EXISTS orders;
CREATE TABLE IF NOT EXISTS orders (order_date TEXT);
INSERT INTO orders (order_date) VALUES
(strftime('%Y-%m-%d','now','-1 days')||' 11:59'), -- before
(strftime('%Y-%m-%d','now')||' 00:00'), -- before
(strftime('%Y-%m-%d','now')||' 11:59'), -- before (just)
(strftime('%Y-%m-%d','now')||' 12:00'), --*** included
(strftime('%Y-%m-%d','now')||' 23:59'), --*** included
(strftime('%Y-%m-%d','now','+1 days')||' 05:00'), --**** included
(strftime('%Y-%m-%d','now','+1 days')||' 05:01') -- after (just)
;
SELECT * FROM orders
WHERE order_date
BETWEEN (strftime('%Y-%m-%d','now')||' 12:00')
AND (strftime('%Y-%m-%d','now','+1 days')||' 05:00')
;
- Those marked with *** are rows (3 of them) that should be selected.
I want to start current day from noon 12PM so i will change00:00
to12:00
right?
– Beeman
20 hours ago
i don't have AM or PM myOrder_Date
format isYYYY-MM-DD HH:mm
example2018-11-08 14:00
– Beeman
20 hours ago
@Beeman yep sorry missed 12PM. However the AM/PM makes things a little more difficult (need to add 12 hours for PM). Working on that now.
– MikeT
20 hours ago
@Beeman in the example you included. However, makes life easier to not have so won't change (might edit your post to remove AM PM so as not to confuse.)
– MikeT
20 hours ago
@Beeman answer edited accordingly for 12:00
– MikeT
20 hours ago
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
I believe the following could be used :-
SELECT * FROM orders
WHERE order_date
BETWEEN (strftime('%Y-%m-%d','now')||' 12:00')
AND (strftime('%Y-%m-%d','now','+1 days')||' 05:00')
;
Working Example
DROP TABLE IF EXISTS orders;
CREATE TABLE IF NOT EXISTS orders (order_date TEXT);
INSERT INTO orders (order_date) VALUES
(strftime('%Y-%m-%d','now','-1 days')||' 11:59'), -- before
(strftime('%Y-%m-%d','now')||' 00:00'), -- before
(strftime('%Y-%m-%d','now')||' 11:59'), -- before (just)
(strftime('%Y-%m-%d','now')||' 12:00'), --*** included
(strftime('%Y-%m-%d','now')||' 23:59'), --*** included
(strftime('%Y-%m-%d','now','+1 days')||' 05:00'), --**** included
(strftime('%Y-%m-%d','now','+1 days')||' 05:01') -- after (just)
;
SELECT * FROM orders
WHERE order_date
BETWEEN (strftime('%Y-%m-%d','now')||' 12:00')
AND (strftime('%Y-%m-%d','now','+1 days')||' 05:00')
;
- Those marked with *** are rows (3 of them) that should be selected.
I believe the following could be used :-
SELECT * FROM orders
WHERE order_date
BETWEEN (strftime('%Y-%m-%d','now')||' 12:00')
AND (strftime('%Y-%m-%d','now','+1 days')||' 05:00')
;
Working Example
DROP TABLE IF EXISTS orders;
CREATE TABLE IF NOT EXISTS orders (order_date TEXT);
INSERT INTO orders (order_date) VALUES
(strftime('%Y-%m-%d','now','-1 days')||' 11:59'), -- before
(strftime('%Y-%m-%d','now')||' 00:00'), -- before
(strftime('%Y-%m-%d','now')||' 11:59'), -- before (just)
(strftime('%Y-%m-%d','now')||' 12:00'), --*** included
(strftime('%Y-%m-%d','now')||' 23:59'), --*** included
(strftime('%Y-%m-%d','now','+1 days')||' 05:00'), --**** included
(strftime('%Y-%m-%d','now','+1 days')||' 05:01') -- after (just)
;
SELECT * FROM orders
WHERE order_date
BETWEEN (strftime('%Y-%m-%d','now')||' 12:00')
AND (strftime('%Y-%m-%d','now','+1 days')||' 05:00')
;
- Those marked with *** are rows (3 of them) that should be selected.
edited 20 hours ago
answered 20 hours ago
MikeT
12.9k102440
12.9k102440
I want to start current day from noon 12PM so i will change00:00
to12:00
right?
– Beeman
20 hours ago
i don't have AM or PM myOrder_Date
format isYYYY-MM-DD HH:mm
example2018-11-08 14:00
– Beeman
20 hours ago
@Beeman yep sorry missed 12PM. However the AM/PM makes things a little more difficult (need to add 12 hours for PM). Working on that now.
– MikeT
20 hours ago
@Beeman in the example you included. However, makes life easier to not have so won't change (might edit your post to remove AM PM so as not to confuse.)
– MikeT
20 hours ago
@Beeman answer edited accordingly for 12:00
– MikeT
20 hours ago
add a comment |
I want to start current day from noon 12PM so i will change00:00
to12:00
right?
– Beeman
20 hours ago
i don't have AM or PM myOrder_Date
format isYYYY-MM-DD HH:mm
example2018-11-08 14:00
– Beeman
20 hours ago
@Beeman yep sorry missed 12PM. However the AM/PM makes things a little more difficult (need to add 12 hours for PM). Working on that now.
– MikeT
20 hours ago
@Beeman in the example you included. However, makes life easier to not have so won't change (might edit your post to remove AM PM so as not to confuse.)
– MikeT
20 hours ago
@Beeman answer edited accordingly for 12:00
– MikeT
20 hours ago
I want to start current day from noon 12PM so i will change
00:00
to 12:00
right?– Beeman
20 hours ago
I want to start current day from noon 12PM so i will change
00:00
to 12:00
right?– Beeman
20 hours ago
i don't have AM or PM my
Order_Date
format is YYYY-MM-DD HH:mm
example 2018-11-08 14:00
– Beeman
20 hours ago
i don't have AM or PM my
Order_Date
format is YYYY-MM-DD HH:mm
example 2018-11-08 14:00
– Beeman
20 hours ago
@Beeman yep sorry missed 12PM. However the AM/PM makes things a little more difficult (need to add 12 hours for PM). Working on that now.
– MikeT
20 hours ago
@Beeman yep sorry missed 12PM. However the AM/PM makes things a little more difficult (need to add 12 hours for PM). Working on that now.
– MikeT
20 hours ago
@Beeman in the example you included. However, makes life easier to not have so won't change (might edit your post to remove AM PM so as not to confuse.)
– MikeT
20 hours ago
@Beeman in the example you included. However, makes life easier to not have so won't change (might edit your post to remove AM PM so as not to confuse.)
– MikeT
20 hours ago
@Beeman answer edited accordingly for 12:00
– MikeT
20 hours ago
@Beeman answer edited accordingly for 12:00
– MikeT
20 hours ago
add a comment |
Beeman is a new contributor. Be nice, and check out our Code of Conduct.
Beeman is a new contributor. Be nice, and check out our Code of Conduct.
Beeman is a new contributor. Be nice, and check out our Code of Conduct.
Beeman is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203213%2fhow-to-select-sales-from-12pm-today-to-next-day-5am-in-sqlite%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
@vizsatiz sqlite doesn't have a "datetime" type. If OP is storing timestamps as strings,
TEXT
is the appropriate type. (Personally, I'd use the unix time in anINTEGER
affinity column instead)– Shawn
21 hours ago
Show what you've tried already in your query.
– Shawn
21 hours ago
@vizsatiz sqlite doesn't support datetime and i have seen the best datatype is
TEXT
for storing datetime in sqlite.– Beeman
21 hours ago