Hello,
I have one form with a field for entering a date 'orderdate' and another field for entering a days interval 'range'.
This form is used to preform a query on a travel tickets database, so that I can search for tickets with dates from ('orderdate') till ('orderdate' + 'range').
For achieving this I have the followiong code:
[php]
"SELECT * FROM viajes WHERE viajes.fecha BETWEEN DATEADD(Day,'". $_GET['rango'] ."','". $_GET['orderdate'] ."') AND '". $_GET['orderdate'] ."'";
[/php]
but Iam getting this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(Day,'4','2008-03-29') AND '2008-03-29' LIMIT 0, 10' at line 1
I dont know if maybe I should use the mysql function DATE_ADD instead of sql DATEADD function,?
Any help is welcome.
note: at least the information from my form seems to be correctly coded in the query: 2008-03-29, as the error shows
4 17741
Hi, es, your query syntax is worng to add the date. So try with the following query. -
SELECT *
-
FROM viajes
-
WHERE
-
viajes.fecha BETWEEN orderdate AND DATE_ADD(orderdate,INTERVAL rango DAY);
Here,
[php]rango = $_GET['rango']
orderdate = $_GET['orderdate'][/php]
So u can format the query as per the PHP concatination syntax.
For general, date add function
Syntax: - DATE_ADD(date,INTERVAL expr unit);
Example: - SELECT DATE_ADD(DATE(NOW()),INTERVAL 2 DAY) AS DT;
I hope.. this will help you...
Good Luck...
Regards,
S.Ashokkumar
Please enclose your posted code in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use [code] tags in future.
MODERATOR
Hi, es, your query syntax is worng to add the date. So try with the following query. -
SELECT *
-
FROM viajes
-
WHERE
-
viajes.fecha BETWEEN orderdate AND DATE_ADD(orderdate,INTERVAL rango DAY);
Here,
[php]rango = $_GET['rango']
orderdate = $_GET['orderdate'][/php]
So u can format the query as per the PHP concatination syntax.
For general, date add function
Syntax: - DATE_ADD(date,INTERVAL expr unit);
Example: - SELECT DATE_ADD(DATE(NOW()),INTERVAL 2 DAY) AS DT;
I hope.. this will help you...
Good Luck...
Regards,
S.Ashokkumar
Ok thanks a lot, it works now. This is the code I use: - "SELECT * FROM viajes WHERE viajes.fecha BETWEEN '". $_GET['orderdate'] ."' AND DATE_ADD('". $_GET['orderdate'] ."',INTERVAL '". $_GET['rango'] ."' day)";
Could you tell me why I had to use the DATE_ADD instead of the DATEADD function? I think I am lost in between SQL and MYSQL
....Could you tell me why I had to use the DATE_ADD instead of the DATEADD function? I think I am lost in between SQL and MYSQL
DATEADD does not exist as a MySQL function, DATE_ADD is the correct one.
Btw rodrigo21: what is your comment on the reply to a previous thread of yours at this link http://www.thescripts.com/forum/post3115825-16.html ?
Ronald
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Gabe |
last post by:
Please see: http://www.showorders.com/test3.asp
The code generating the page is as follows:
testdate = "1/29/2003 1:00:00 PM"
while count <> 5
testdate = dateadd("n",15,testdate)...
|
by: Zlatko Matiæ |
last post by:
I am currently migrating from MSDE to PostgreSQL and have to rewrite the
function that is calculating next date of sampling...
In MSDE there is a DateAdd function. I can't find the appropriate...
|
by: Abdul N K |
last post by:
I need help in T-SQL.
I am using DATEADD function and I want to add 6 months to a date. But
it does not return me the rusults, which I want
e.g. SELECT DATEADD(m,'20040630') returns 20041230...
|
by: ey.markov |
last post by:
Greetings,
I have an A2K application where for a report the user enters a
month-end date, and the system must gather transactions for that month.
No problem, I thought, I'll just use the DateAdd...
|
by: C.Davidson |
last post by:
Does subject VB.net 2003 support DateAdd function? I have tried to
implement the following without success. In my example I tried to
simply add 30 months to 9/18/2003 and I get "New date: 12:00:00...
|
by: Zlatko Matiæ |
last post by:
I am currently migrating from MSDE to PostgreSQL and have to rewrite the
function that is calculating next date of sampling...
In MSDE there is a DateAdd function. I can't find the appropriate...
|
by: Rich Raffenetti |
last post by:
I have the following code. If I do the dateadd function with
dateinterval.minute, it works fine and the date/time value is displayed with
zero seconds. If I do the dateadd function with...
|
by: kevinSQL |
last post by:
Is it possible to dynamically modify the Datepart argument of the DATEADD function in T-SQL 2005.
I am trying to do something like this but it's not happy with parameter 1:
DECLARE @pp...
|
by: Mel |
last post by:
When I use the DateAdd function using "DateInterval.Weekday" it does
not return the correct date, well at least how I thought the weekday
option should work. It is counting weekends and I only...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| | |