473,480 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

problem in using strtotime in query mysql

oranoos3000
107 New Member
hi
i work with php and mysql on the os windows
i want to using function strtotime for compute diffrences between
two date , one with format date("Y-F-d") and another date is current time
and query is
Expand|Select|Wrap|Line Numbers
  1. $sql_select="select * from $table_name  where  confirm=1 and ";
  2. $sql_select.=strtotime."(".expire_date_show.") - ".time().">=0";
  3. //expire_date_show is the column in database with format date("Y-F-d")
  4.  
but this query select and show all of the query even they that epire_date_show
is greater than current time
please help me that how write this query to solve this problem
Jan 17 '09 #1
3 9674
Atli
5,058 Recognized Expert Expert
Hi.

You can not fuse a PHP function into a MySQL query in that manner.
The data returned by a SQL query can not be used by your PHP code until the query has been executed and the data returned.

I'm betting that if you put these two lines at the top of your code, so that errors will be displayed, that you will get a "undefined constant" warning for the strtotime function. (And probably "expire_date_show" to).
Expand|Select|Wrap|Line Numbers
  1. error_reporting(E_ALL | E_STRICT);
  2. ini_set('display_errors', true);
In any case, you do not need the strotime function to do this. MySQL is capable of doing this all by itself.
Consider this:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM myTable
  2. WHERE `DateValue` > NOW()
This would return only those rows from the "myTable" table where the "DateValue" is greater then the current date.
Jan 17 '09 #2
oranoos3000
107 New Member
hi
excuse me
in your answer
DateValue that one of the columln in table in db,what is data type of this column and format amount of this column?
because
i want to save two date in the table
and compare current time with two date and if current time is between
two date then show this record


thanks


@Atli
Jan 18 '09 #3
Atli
5,058 Recognized Expert Expert
The "DateValue" column in my example would be either a DATE, DATETIME or TIMESTAMP. They should all work.

The good thing about using these types for dates (as apposed to using strings or integers) is that MySQL has a lot of date functions that are specifically built to manipulate them.
If you store dates as strings or integers you won't be able to use them and all manipulation would have to be done manually by your front-end.

If you need to find out whether a value is between a pair of other values, you can use the BETWEEN AND syntax.
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM myTable
  2. WHERE DateValue BETWEEN  NOW() AND DATE_ADD(NOW(), INTERVAL 1 DAY);
This would return all rows who's DateValue is between the current time and the same time tomorrow.
Jan 18 '09 #4

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

Similar topics

1
2886
by: André Gasser | last post by:
hello newsgroup, I just discovered a weird effect in my php code. here is the flow of my code: 1. upload jepg file to server 2. create new (empty) jpeg file using imagecreatefromjpeg()...
3
9881
by: David | last post by:
Hi, I have an asp page running from a mysql db. A line in my asp code runs as follows: .........WHERE ShipDate >= curdate() This displays the data until 'shipdate' (from the database) is...
10
14021
by: Randell D. | last post by:
Folks, I have a SELECT that returns with multiple records - It works when I have a LIMIT clause but when I try to include a GROUP BY clause, the select returns nothing (ie no records, no...
1
1418
by: Faisal Yaqoob | last post by:
I am using MySQL ODBC driver and System.Data.Odbc package to connect to database. I am using OdbcDataReader to read the recordset returned as a result of a query. I do check if the column value...
2
18286
by: ameshkin | last post by:
Hi GUys, Im trying to compare two dates in MYSQL. But its not treating the dates as numbers, but as strings. I try using strtotime but that did not work. Basically, if the last comment is...
2
2692
cassbiz
by: cassbiz | last post by:
I am using strtotime and I have read up on some examples and am getting the wrong output, it jumps by several days instead of one day at a time. Ultimately what I am trying to accomplish is to set...
6
38905
by: Brandon | last post by:
I'm using PHP with MySQL 4.x and was having trouble converting a datetime from MySQL into a formatted string until I ran across this solution that converts a YYYY-MM-DD HH:MM:SS string into a...
4
6803
by: karthikeyanck | last post by:
How to query MySQL from a web browser URL. I 've a Apache server running on my Ubuntu machine which has PHP and MySQL installed. I 've an assignment to demonstrate how SQL Injection works, I...
1
3098
by: giovannino | last post by:
Dear all, I did a query which update a sequence number (column NR_SEQUENZA) in a table using a nice code (from Trevor !). 1) Given that I'm not a programmer I can't understand why...
1
2485
by: Jordan Boden | last post by:
Hi, I have a problem trying to prevent a time slot and seat number being double booked. I am using PHP and MySQL for this. Currently I have no errors concerning variable names or issues with...
0
6911
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
7050
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,...
1
6743
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
5344
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,...
1
4787
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2988
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
564
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.