Query related

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sandy1028
Forum Commoner
Posts: 60
Joined: Thu Jul 26, 2007 3:56 am

Query related

Post by sandy1028 »

Hi,

How to find the values of exactly one day old data from curtime()

Suppose time() is 12:40:56 to find data between time() and previous day 12:40:56.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Subtract a day from that time. It's generally held that there are 24 hours in a day, 60 minutes in a hour and 60 seconds in a minute.
sandy1028
Forum Commoner
Posts: 60
Joined: Thu Jul 26, 2007 3:56 am

Post by sandy1028 »

feyd wrote:Subtract a day from that time. It's generally held that there are 24 hours in a day, 60 minutes in a hour and 60 seconds in a minute.
I used the query

select * from `table_name` where `fieldname` < now() and `fieldname` > now()-interval 1 day


But I am not getting exactly 24hours data.

I am getting the data from cur timestamp till previous day data till 2007-09-13 00:00:00

How to get exactly 24 hours data from current timestamp
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

You could use php to make a timestamp - mktime() or date()
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
sandy1028
Forum Commoner
Posts: 60
Joined: Thu Jul 26, 2007 3:56 am

Post by sandy1028 »

scottayy wrote:You could use php to make a timestamp - mktime() or date()
Is it not possible in mysql query
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

feyd wrote:Subtract a day from that time. It's generally held that there are 24 hours in a day, 60 minutes in a hour and 60 seconds in a minute.
Not in Canada, we're on metric time.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Kieran Huggins wrote:Not in Canada, we're on metric time.
True, that would be 3 hexahours a day, 48 decaminutes per hexahour, and 60 decaseconds per decaminute.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

sandy1028 wrote:
scottayy wrote:You could use php to make a timestamp - mktime() or date()
Is it not possible in mysql query
It is possible if the query is in a php script. If it is not, then ignore me. :)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

feyd wrote:
Kieran Huggins wrote:Not in Canada, we're on metric time.
True, that would be 3 hexahours a day, 48 decaminutes per hexahour, and 60 decaseconds per decaminute.
I think Canada has 10 deca-ehs in a day with 100 milli-ehs in a deca-eh. That's because a Canuck can polish off a two-four faster those hexa hosers.
(#10850)
mrkite
Forum Contributor
Posts: 104
Joined: Tue Sep 11, 2007 4:19 am

Post by mrkite »

sandy1028 wrote:
select * from `table_name` where `fieldname` < now() and `fieldname` > now()-interval 1 day


But I am not getting exactly 24hours data.

I am getting the data from cur timestamp till previous day data till 2007-09-13 00:00:00

How to get exactly 24 hours data from current timestamp

It could be because you're using a bit of a non-standard way of doing your time manips.

Code: Select all

select * from table where field <= now() and field> date_sub(now(),interval 1 day)
Post Reply