473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Get data less than 24 hours from current date

250 100+
I want to get data less than 24 hours from the current date. This is my query. But i get wrong output. It display 2008-07-22 data and 2008-05-15 data also. Could some one help me?


[PHP]SELECT Rainfall,Date FROM rainfall WHERE TIMEDIFF('".$today."', Date) < '24:00:00' AND Station_ID= '$GStationID' ORDER BY Date ";[/PHP]
Jul 22 '08 #1
4 9157
coolsti
310 100+
I want to get data less than 24 hours from the current date. This is my query. But i get wrong output. It display 2008-07-22 data and 2008-05-15 data also. Could some one help me?


[PHP]SELECT Rainfall,Date FROM rainfall WHERE TIMEDIFF('".$today."', Date) < '24:00:00' AND Station_ID= '$GStationID' ORDER BY Date ";[/PHP]
It would help if you also tell us the following: What is Date? A Date field or Datetime field? What value does $today take on? The format may be important.

Why don't you just let mysql calculate a value for $today? You can maybe use the NOW() function in mysql.
Jul 22 '08 #2
ghjk
250 100+
It would help if you also tell us the following: What is Date? A Date field or Datetime field? What value does $today take on? The format may be important.

Why don't you just let mysql calculate a value for $today? You can maybe use the NOW() function in mysql.


Date= datetime field
$today = current date
ex:[PHP]$today = date("Y-m-d H:i:s");[/PHP]
Jul 22 '08 #3
Atli
5,058 Expert 4TB
Try something like:
Expand|Select|Wrap|Line Numbers
  1. SELECT cols FROM table WHERE dateCol > DATE_SUB(NOW(), INTERVAL 1 DAY);
  2. /* OR, if your going into the future*/
  3. SELECT cols FROM table WHERE dateCol < DATE_ADD(NOW(), INTERVAL 1 DAY);
  4.  
It's all in the manual.
Jul 23 '08 #4
ghjk
250 100+
Try something like:
Expand|Select|Wrap|Line Numbers
  1. SELECT cols FROM table WHERE dateCol > DATE_SUB(NOW(), INTERVAL 1 DAY);
  2. /* OR, if your going into the future*/
  3. SELECT cols FROM table WHERE dateCol < DATE_ADD(NOW(), INTERVAL 1 DAY);
  4.  
It's all in the manual.

Thank You. It works!
Jul 23 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: John Norvell | last post by:
I just noticed that recently the javascript I was using to format and display the last modified date of my web page is always reporting the current date instead. It used to work fine. This is true...
2
by: William Wisnieski | last post by:
Hi Everyone, Access 2000 I have some code behind a button that performs a word merge with a query data source. The merge works fine. But what I'd like to do somehow is after the merge is...
4
by: Bill Burke | last post by:
I'm very new to Visual C# .NET and would appreciate any help. I am using Visual Studio .NET 2003. I want to display the current date from the user system in a web form. I have spent hours...
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
1
by: tomzji | last post by:
I am using Sql server 2005. I have one table named 'tblJob'. This table have two fields say 'Staus' and 'ExpiryDate'. when 'Expirydate' come to less than current date, i want to upadte 'Status'...
3
by: lyndac | last post by:
Hello! Last night a job to create a view using DATE(CURRENT DATE - 1 DAY) received the current days date instead the previous days date. Any one know why/how this can happen? The...
3
by: ahd2008 | last post by:
Hi everybody, I want to create a code that subtract two years from the current date and returns the data. For instance Current date= 05/05/2009 Date before two years=current date-(2 years)...
3
by: perhapscwk | last post by:
I using a insert query to insert some data into mysql. I use now() as the current date and time but it always have 3.X hours different from actual date. what i should use instead? thanks.
0
by: Souniel Gaikwad | last post by:
I want save current date in my table. For that i was used System.DateTime.Now.ToShortDateString(); but it gives following error: The conversion of a char data type to a datetime data type...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.