User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 391,774 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,446 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 1076 | Replies: 6 | Solved
Reply
Join Date: Mar 2008
Posts: 55
Reputation: forzadraco is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
forzadraco forzadraco is offline Offline
Junior Poster in Training

datetime query

  #1  
May 27th, 2008
range of datetime data type (show all records in between 2 dates. example: form
2008/10/01 to 2008./12/12). thanks
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2008
Posts: 3
Reputation: marrrrrrc is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
marrrrrrc marrrrrrc is offline Offline
Newbie Poster

Re: datetime query

  #2  
May 27th, 2008
SELECT * FROM date BETWEEN '2008-10-01' AND '2008-12-12'

http://dev.mysql.com/doc/refman/5.0/...erator_between
Last edited by marrrrrrc : May 27th, 2008 at 8:33 am.
Reply With Quote  
Join Date: Dec 2007
Posts: 107
Reputation: mwasif is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 13
mwasif mwasif is offline Offline
Junior Poster

Re: datetime query

  #3  
May 27th, 2008
If the data type is datetime, then you must include time in the query
  1. SELECT * FROM table WHERE date_col BETWEEN '2008-10-01 00-00-00' AND '2008-12-12 23:59:59'
Last edited by mwasif : May 27th, 2008 at 2:31 pm.
Reply With Quote  
Join Date: Jul 2008
Posts: 2
Reputation: Matthewanxa is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
Matthewanxa Matthewanxa is offline Offline
Newbie Poster

Re: datetime query

  #4  
30 Days Ago
I need help please with a similar issue but in my case I don't want a specific date.

I need to query all records created yesterday.

Since the get date function only finds records with the exact minute and second I need to use a range. Less than current date but greater than 23 hours 59 minutes old.

How can I write this query please?

THank you

Matthew

Originally Posted by mwasif View Post
If the data type is datetime, then you must include time in the query
  1. SELECT * FROM table WHERE date_col BETWEEN '2008-10-01 00-00-00' AND '2008-12-12 23:59:59'
Reply With Quote  
Join Date: Jul 2008
Location: Hyderabad,India.
Posts: 522
Reputation: Shanti Chepuru is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 53
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is online now Online
Posting Pro

Re: datetime query

  #5  
30 Days Ago
  1. SELECT * FROM table WHERE date_col<curdate() AND date>DATE_ADD(CURDATE(), INTERVAL -1 DAY)
Last edited by Shanti Chepuru : 30 Days Ago at 2:43 am. Reason: add code tags
Champions Are Not SuperNatural,They Just Fought For One More Second When Every One Else Quit...Some times That One Second Of Effort Gives You The VICTORY...
Reply With Quote  
Join Date: Jul 2008
Posts: 2
Reputation: Matthewanxa is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
Matthewanxa Matthewanxa is offline Offline
Newbie Poster

Re: datetime query

  #6  
29 Days Ago
Thank you very much for your help.

I was able to solve it in fact with datediff(date_col,getdate()) = -1

We are running mssql

Best regards,

Matthew

Originally Posted by Shanti Chepuru View Post
  1. SELECT * FROM table WHERE date_col<curdate() AND date>DATE_ADD(CURDATE(), INTERVAL -1 DAY)
Reply With Quote  
Join Date: Jul 2008
Location: Hyderabad,India.
Posts: 522
Reputation: Shanti Chepuru is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 53
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is online now Online
Posting Pro

Re: datetime query

  #7  
29 Days Ago
make this thread as solved...
Champions Are Not SuperNatural,They Just Fought For One More Second When Every One Else Quit...Some times That One Second Of Effort Gives You The VICTORY...
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 4:50 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC