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










share|improve this question









New contributor




Beeman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • @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










  • @vizsatiz sqlite doesn't support datetime and i have seen the best datatype is TEXT for storing datetime in sqlite.
    – Beeman
    21 hours ago















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










share|improve this question









New contributor




Beeman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • @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










  • @vizsatiz sqlite doesn't support datetime and i have seen the best datatype is TEXT for storing datetime in sqlite.
    – Beeman
    21 hours ago













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










share|improve this question









New contributor




Beeman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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






share|improve this question









New contributor




Beeman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Beeman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 18 hours ago









MikeT

12.9k102440




12.9k102440






New contributor




Beeman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 22 hours ago









Beeman

82




82




New contributor




Beeman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Beeman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Beeman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • @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










  • @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 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










  • @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 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












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.
    enter image description here






share|improve this answer























  • 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










  • @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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Beeman is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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
































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.
    enter image description here






share|improve this answer























  • 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










  • @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















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.
    enter image description here






share|improve this answer























  • 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










  • @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













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.
    enter image description here






share|improve this answer














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.
    enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








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 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










  • @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 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 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










Beeman is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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.















 


draft saved


draft discarded














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




















































































Popular posts from this blog

Schultheiß

Liste der Kulturdenkmale in Wilsdruff

Android Play Services Check