473,327 Members | 1,952 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,327 software developers and data experts.

adding dates, DATEADD function

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
Mar 29 '08 #1
4 17741
Hi, es, your query syntax is worng to add the date. So try with the following query.
Expand|Select|Wrap|Line Numbers
  1. SELECT * 
  2. FROM     viajes 
  3. WHERE     
  4.     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:
Expand|Select|Wrap|Line Numbers
  1. DATE_ADD(date,INTERVAL expr unit);
Example:
Expand|Select|Wrap|Line Numbers
  1. SELECT DATE_ADD(DATE(NOW()),INTERVAL 2 DAY) AS DT;
I hope.. this will help you...
Good Luck...

Regards,
S.Ashokkumar
Mar 29 '08 #2
ronverdonk
4,258 Expert 4TB
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
Mar 29 '08 #3
Hi, es, your query syntax is worng to add the date. So try with the following query.
Expand|Select|Wrap|Line Numbers
  1. SELECT * 
  2. FROM     viajes 
  3. WHERE     
  4.     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:
Expand|Select|Wrap|Line Numbers
  1. DATE_ADD(date,INTERVAL expr unit);
Example:
Expand|Select|Wrap|Line Numbers
  1. 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:

Expand|Select|Wrap|Line Numbers
  1. "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
Mar 29 '08 #4
ronverdonk
4,258 Expert 4TB
....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
Mar 29 '08 #5

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

Similar topics

3
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)...
0
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...
2
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...
4
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...
1
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...
0
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...
2
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...
1
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...
3
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...
1
isladogs
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...
0
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...
1
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)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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....
0
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
0
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...
0
isladogs
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...

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.