5 Replies - 692 Views - Last Post: 12 December 2008 - 11:42 PM Rate Topic: -----

#1 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Date problem in query

Post icon  Posted 08 December 2008 - 11:38 PM

Select * from table Name where KTDT< DATAEADD(MONTH,-2,DATE)

THIS QUERY IS NOT WORKING. KTDT IS COLUMN CONTAINS DIFFERENT DATES

WT I WANT IS THAT i want to retrieve data which are 2 months older than current system date
Is This A Good Question/Topic? 0
  • +

Replies To: Date problem in query

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4306
  • View blog
  • Posts: 12,079
  • Joined: 18-April 07

Re: Date problem in query

Posted 09 December 2008 - 12:19 AM

Try...

Select * from table Name where KTDT< DATEADD(mm,-2,getdate())



This is saying subtract 2 months from the current date. Also make sure you spell DATEADD correctly. In your example you have an extra "A" in there.

Oh and in the future, please refrain from typing in all caps. It really does make the question look lame.

Thanks! ;)
Was This Post Helpful? 0
  • +
  • -

#3 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Re: Date problem in query

Posted 09 December 2008 - 12:45 AM

View PostMartyr2, on 8 Dec, 2008 - 11:19 PM, said:

Try...

Select * from table Name where KTDT< DATEADD(mm,-2,getdate())



This is saying subtract 2 months from the current date. Also make sure you spell DATEADD correctly. In your example you have an extra "A" in there.

Oh and in the future, please refrain from typing in all caps. It really does make the question look lame.

Thanks! ;)



it is giving error

undefined function "getdate" in expression.

format of date in database is -- mm/dd/yyyy 12/04/2008

This post has been edited by vks.gautam1: 09 December 2008 - 12:49 AM

Was This Post Helpful? 0
  • +
  • -

#4 Trogdor  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 15
  • View blog
  • Posts: 627
  • Joined: 06-October 06

Re: Date problem in query

Posted 09 December 2008 - 05:09 AM

What database brand are you using?
Was This Post Helpful? 0
  • +
  • -

#5 P4L  Icon User is offline

  • Your worst nightmare
  • member icon

Reputation: 34
  • View blog
  • Posts: 2,788
  • Joined: 07-February 08

Re: Date problem in query

Posted 09 December 2008 - 06:05 AM

View Postvks.gautam1, on 8 Dec, 2008 - 11:45 PM, said:

View PostMartyr2, on 8 Dec, 2008 - 11:19 PM, said:

Try...

Select * from table Name where KTDT< DATEADD(mm,-2,getdate())



This is saying subtract 2 months from the current date. Also make sure you spell DATEADD correctly. In your example you have an extra "A" in there.

Oh and in the future, please refrain from typing in all caps. It really does make the question look lame.

Thanks! ;)



it is giving error

undefined function "getdate" in expression.

format of date in database is -- mm/dd/yyyy 12/04/2008


It sounds like you might be using Access for your database in which case the code would look like this.

Select * from table Name where KTDT< DATEADD(mm,-2,date())


Was This Post Helpful? 0
  • +
  • -

#6 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Re: Date problem in query

Posted 12 December 2008 - 11:42 PM

Im Using MsAccess.

This is the the code which works .

DateAdd('m',-2,date())

This post has been edited by vks.gautam1: 12 December 2008 - 11:43 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1