query datestamp for last 24 hours

  • Follow


Hi

I have a mysql table that automatically date stamps new entries like
this: 2008-03-20 10:02:13 (year-month-day-time)

how would I write a query to find all entires in the last 24 hours, I
know I can find it based on the exact date by using this:

SELECT * FROM `table` WHERE `datestamp` = '2008-03-20 10:02:13'

but I have no idea how to tell it to get everything from the last 24
hours

Thanks
0
Reply canajien 3/20/2008 2:08:06 PM

On Mar 20, 10:08 am, "canaj...@gmail.com" <canaj...@gmail.com> wrote:
> Hi
>
> I have a mysql table that automatically date stamps new entries like
> this: 2008-03-20 10:02:13 (year-month-day-time)
>
> how would I write a query to find all entires in the last 24 hours, I
> know I can find it based on the exact date by using this:
>
> SELECT * FROM `table` WHERE `datestamp` = '2008-03-20 10:02:13'
>
> but I have no idea how to tell it to get everything from the last 24
> hours
>
> Thanks

select *
from table
where datestamp between adddate('2008-03-20 10:02:13', -1) and
'2008-03-20 10:02:13'
0
Reply ZeldorBlat 3/20/2008 2:20:55 PM


On 20 Mar, 14:20, ZeldorBlat <zeldorb...@gmail.com> wrote:
> On Mar 20, 10:08 am, "canaj...@gmail.com" <canaj...@gmail.com> wrote:
>
> > Hi
>
> > I have a mysql table that automatically date stamps new entries like
> > this: 2008-03-20 10:02:13 (year-month-day-time)
>
> > how would I write a query to find all entires in the last 24 hours, I
> > know I can find it based on the exact date by using this:
>
> > SELECT * FROM `table` WHERE `datestamp` = '2008-03-20 10:02:13'
>
> > but I have no idea how to tell it to get everything from the last 24
> > hours
>
> > Thanks
>
> select *
> from table
> where datestamp between adddate('2008-03-20 10:02:13', -1) and
> '2008-03-20 10:02:13'

I don't think that will do it.
SELECT * FROM `table` WHERE `datestamp` > NOW() - INTERVAL 24 HOUR
0
Reply Captain 3/20/2008 4:06:18 PM

On Mar 20, 12:06 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 20 Mar, 14:20, ZeldorBlat <zeldorb...@gmail.com> wrote:
>
>
>
> > On Mar 20, 10:08 am, "canaj...@gmail.com" <canaj...@gmail.com> wrote:
>
> > > Hi
>
> > > I have a mysql table that automatically date stamps new entries like
> > > this: 2008-03-20 10:02:13 (year-month-day-time)
>
> > > how would I write a query to find all entires in the last 24 hours, I
> > > know I can find it based on the exact date by using this:
>
> > > SELECT * FROM `table` WHERE `datestamp` = '2008-03-20 10:02:13'
>
> > > but I have no idea how to tell it to get everything from the last 24
> > > hours
>
> > > Thanks
>
> > select *
> > from table
> > where datestamp between adddate('2008-03-20 10:02:13', -1) and
> > '2008-03-20 10:02:13'
>
> I don't think that will do it.
> SELECT * FROM `table` WHERE `datestamp` > NOW() - INTERVAL 24 HOUR

Thank you!!! This is exactly what I was looking for
0
Reply canajien 3/20/2008 4:51:27 PM

3 Replies
254 Views

(page loaded in 0.121 seconds)

5/22/2013 1:07:59 PM


Reply: