Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datepart query

Status
Not open for further replies.

jeffwest2

MIS
Feb 5, 2009
64
GB
I am trying to determine how old something is, using this formula

if datepart("d",{SITUATIO.Start Date}) >= (datepart("d",CurrentDate))-0
and datepart("d",{SITUATIO.Start Date}) <= (datepart("d",CurrentDate))-89
then "<3 months" else
if datepart("d",{SITUATIO.Start Date}) >= (datepart("d",CurrentDate))-90
and datepart("d",{SITUATIO.Start Date}) <= (datepart("d",CurrentDate))-179
then "3 - 6 months" else
if datepart("d",{SITUATIO.Start Date}) >= (datepart("d",CurrentDate))-180
and datepart("d",{SITUATIO.Start Date}) <= (datepart("d",CurrentDate))-364
then "6 - 12 months" else
if datepart("d",{SITUATIO.Start Date}) >= (datepart("d",CurrentDate))-365
then "> 1 Year"

Only problem is, despite having dates that are only a few weeks/months old, it only seems to return the last value.

Anyone help with this please, it really is annoying me.

 
Its because all your data meets the last condition.

YOu need to extend the formulas to exclude the previous data sets.

Ian
 
Sorry, confused, how can everything meet the last value, when i have specified ranges before it, as i said, i have data where the date is only 3 months old, yet it always says it is older than a year
 
May be this formula is wrong

if datepart("d",{SITUATIO.Start Date}) >= (datepart("d",CurrentDate))-365

should be

if datepart("d",{SITUATIO.Start Date}) <= (datepart("d",CurrentDate))-365

Ian
 
That's it, thanks, i had the <= & >= the wrong way round
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top