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 17818
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)
response.write testdate & "<br>"
|
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 function
in postgre. Can you help me?
The function in MSDE is the following:
ALTER FUNCTION dbo.slisp
(
@UCESTALOST_BROJ int,
@UCESTALOST_JEDINICA nvarchar (50),
|
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
which is logical correct? But I want it to return end of month (i.e.
20041231)
Any help in this context will be highly appreciated
|
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 function for the
beginning of the date range, like this:
Between DateAdd("m",-1,!!) And
!!
|
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 AM",
no date
Example direct from VB Language Reference:
Public Overloads Function DateAdd(ByVal Interval As DateInterval,_
ByVal Number As Double, ByVal DateValue As DateTime) As DateTime
End Function
| |
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 function
in postgre. Can you help me?
The function in MSDE is the following:
ALTER FUNCTION dbo.slisp
(
@UCESTALOST_BROJ int,
@UCESTALOST_JEDINICA nvarchar (50),
|
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 dateinterval.second, an
error is thrown saying I have an overflow. I would be happy to know if I am
doing something wrong or if I could do it differently to get the seconds to
display properly.
Const largeInteger As Long = &H1C5EA3B5F585F1F
Const...
|
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 NCHAR(3)
SET @pp = 'day'
SELECT dateadd(@pp,3,'2007-07-14 12:00:00')
Any Ideas will be much appreciated.
|
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 want it to
count the weekdays (Mon-Fri). How can I get it to work? (using
Asp.net 2.0, vb.net)
Example:
dPlanFD = DateAdd(DateInterval.Weekday, 10, "11/04/2008")
'dPlanFD = #11/14/2008# 'I want it to return #11/18/2008#
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |