MYSQL - sql query date time

i have a datestamp field in my table structure. using sql, i want to find any user who registered in yesterdays date using these time range.

eg: 2010-02-06 14:00:00 2010-02-07 10:00:00

i will be running this query once a day to grab users.

so tomorrow will be: 2010-02-07 14:00:00 2010-02-08 10:00:00

the day after tomorrow will be: 2010-02-08 14:00:00 2010-02-09 10:00:00

etc, etc.

select distinct * from users where loggedTime...

not sure how to query the date range? any ideas thanks

This question and answers originated from www.stackoverflow.com
Question by (2/8/2010 12:35:44 AM)

Answer

SQL Server

where loggedTime between
   DATEADD(hour, 14, DATEADD(DAY, 0, DATEDIFF(DAY,0,getdate()))) and
   DATEADD(hour, 34, DATEADD(DAY, 0, DATEDIFF(DAY,0,getdate())))

MySQL

where loggedTime between
   curdate() + interval 14 hour and
   curdate() + interval 34 hour
Answer by

Find More Answers
Related Topics  mysql  sql  query  date  time
Related Questions
  • Date & time query question (SQL Server 2008)

    I have table that contain date and time field. id|date|time ========= 1|01/01/2001|10:45 2|01/02/2002|11:45 3|01/03/2003|12:45 4|01/04/2004|12:55 I need to know the difference between the MAX…
  • SQL Server 2005 Date Time stamp Query

    One of my columns type is DateTime (Date Registered). I cannot create a query that filters all the data for eg. All registrations who registered on the 22/10/2008 between 18:00 and 20:00. Thanks
  • SQL QUERY ( SQL SERVER) Date & Time Difference

    I have a SQL SERVER Table which has only one field "StartDate" the records are as follows ** 2011-07-28 19:30:00.000 2011-07-29 21:50:00.000 2011-07-25 09:20:00.000 ** What i want to do …
  • SQL date intervals query

    I am managing an event database. Every event has a start and end timestamp ( INT, unix timestamp ). Currently i'm able to do the following things with a single SQL query: build up a calendar…
  • SQL Query with Long Date Time?

    I am trying to pass a SQL query through c# , currently it is based on just the day month and year with time always set to 0 EG 1997-10-28 00.00.00.000 which is great as the time never changes it eas…
  • Sql query join nearest date

    I have a sqlite query that I'm trying to write. I have two tables: TableA (sales): id sales date TableB (goals): id goal date I'm selecting from TableA like this: SELECT id,sales,date FROM …
  • Sql query for specific date range and date time

    I need to query all values between specified date range and time range. For example, I want to query all the values from 5:00Pm on 16-Sep-2010 to 9:00AM 21-Sep-2010. Any ideas how the query should b…
  • SQL Time Overlap/Conflict Query

    I have a requirement where I need to assign some resource for some tine frame .For example Existing in Database : John Smith -- 3/1/2011 -- 6:00 AM To 7:00 AM -- Economics To Be Inserted: Jo…
  • sql query with condition on date

    I have a little simple problem. I want to perform a query on a Mysql table to select posts posted after a certain date but I don't manage to get it working by setting that date as a PHP variable. …
  • MySQL time/date calculation

    First, an entry in the database: I have an input form that writes start date, start and end times (in hour and minute) of working days plus lunch break in minutes (in the example dato=date, m…