If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Retrieving records from yesterday night and today morning everyday

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-06-11, 13:07
merryba merryba is offline
Registered User
 
Join Date: Apr 2011
Posts: 3
Retrieving records from yesterday night and today morning everyday

Hi all,

How to write a SQL Query to retrieve count of records each day(by getting sysdate from the system) for records inserted between yesterday night and today morning?

pls. advise

Thanks
Reply With Quote
  #2 (permalink)  
Old 04-06-11, 13:58
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
providng you cna define what yesterday night and today morning is should be straightforward enough
have a look at the MySQL date/time functions
'all' you need to do is build the time banding appropriately
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 04-06-11, 14:10
merryba merryba is offline
Registered User
 
Join Date: Apr 2011
Posts: 3
Retrieving records from yesterday night and today morning everyday

I just want a query like this

select count(*) from table where stamp between (today @ 6 a.m) and (yesterday @ 8 p.m) and I want to use the sysdate for getting today's date as this task will run everyday at some particular time
Reply With Quote
  #4 (permalink)  
Old 04-06-11, 14:45
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
seems reasonable enough
so which verbs/functions/phrases do you think you need from the MySQL date/time functions
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #5 (permalink)  
Old 04-07-11, 02:29
rvijayee rvijayee is offline
Registered User
 
Join Date: Apr 2011
Posts: 1
The below query will display yesterday's date and today's date using current date.

Use this in between the query u are using

select date_ADD(date_sub(CURDATE(), INTERVAL 1 DAY), INTERVAL 20 HOUR), date_ADD(CURDATE(), INTERVAL 6 HOUR)
Reply With Quote
  #6 (permalink)  
Old 04-07-11, 04:20
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
rvijayee, thanks (sarcasm intended) for spoiling healdem's attempt to get merryba to learn how to figure it out for himself

welcome to dbforums and please do read the entire thread before jumping in again
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 04-11-11, 14:38
merryba merryba is offline
Registered User
 
Join Date: Apr 2011
Posts: 3
Thanks rvijayee
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On