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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

best way to figure if "Jan 10" is > 2 months prior

Status
Not open for further replies.

kenndot

Programmer
May 15, 2001
316
US
this is the only information i have is "Jan 10" in a string. I am trying to figure if that date is within 2 months of now.

what I really have here is some files on a unix server that I cannot find a datetime stamp on, this is all i see... if you know of another way, i'm all ears

 
It ain't pretty, but here is one way:
Code:
*... datecheck60.prg ...
PARAMETERS cTemp, dDate
cmo  = Left(cTemp, 3)
cday = Substr(cTemp, 5)

Store 0 To nMonth
Do Case
   Case cmo = 'Jan'
      cMonth = '1'
   Case cmo = 'Feb'
      cMonth = '2'
   Case cmo = 'Mar'
      cMonth = '3'
   Case cmo = 'Apr'
      cMonth = '4'
   Case cmo = 'May'
      cMonth = '5'
   Case cmo = 'Jun'
      cMonth = '6'
   Case cmo = 'Jul'
      cMonth = '7'
   Case cmo = 'Aug'
      cMonth = '8'
   Case cmo = 'Sep'
      cMonth = '9'
   Case cmo = 'Oct'
      cMonth = '10'
   Case cmo = 'Nov'
      cMonth = '11'
   Case cmo = 'Dec'
      cMonth = '12'

ENDCASE
nYear = Iif(Val(cMonth) > Month(dDate), Year(dDate) -1, Year(dDate))
cTemp = cMonth + '/' + cDay + '/' + Alltrim(Str(nYear ))
IF Date() - Ctod(cTemp) > 60
   RETURN .T.
ELSE
   RETURN .F.
ENDIF 
*... EOP:datecheck60 ....

Here are my tests:
?datecheck60("May 10" , Date())
?datecheck60("Jun 10" , Date())
?datecheck60("Jul 10" , Date())
?datecheck60("Aug 10" , Date())
?datecheck60("Sep 10" , Date())
?datecheck60("Oct 10" , Date())
?datecheck60("Nov 10" , Date())
?datecheck60("Dec 10" , Date())
?datecheck60("Nov 20" , Date())
?datecheck60("Nov 21" , Date())
?datecheck60("Nov 22" , Date())


-Dave S.-
[cheers]
Even more Fox stuff at:
 
that's what i was afraid of, i have built something similar, but wasn't sure if anyone knew of a nicer way

thank you much
 
hmm..that solution almost works. Convert the month string to a number (1, 2, 3, etc) then use a loop with GOMONTH().

Craig Berntson
MCSD, Visual FoxPro MVP, Author, CrysDev: A Developer's Guide to Integrating Crystal Reports"
 
kenndot,

I would do it this way (I briefly tested it, seems to work):

theString="Mar 22"
?CheckDate(theString)

FUNCTION CheckDate
PARAMETER xStr
theDate=DATE()
theYear=YEAR(theDate)

nDay=VAL(RIGHT(theString,2))
nMonth=(AT(LEFT(PROPER(theString),3), ;
"JanFebMarAprMayJunJulAugSepOctNovDec")+2)/3
nYear=IIF(nMonth<MONTH(theDate), theYear+1, ;
IIF(nDay<=DAY(theDate) AND nMonth=MONTH(theDate), ;
theYear+1, theYear))
nDate=DATE(nYear, nMonth, nDay)
RETURN IIF(nDate>theDate AND nDate<GOMONTH(theDate,2), .T., .F.)
ENDFUNC

Stella
 
My mistake, it should be looking like this, but you got the idea:

xStr=&quot;Mar 22&quot;
?CheckDate(xStr)

FUNCTION CheckDate
PARAMETER theString
theDate=DATE()
theYear=YEAR(theDate)

nDay=VAL(RIGHT(theString,2))
nMonth=(AT(LEFT(PROPER(theString),3), ;
&quot;JanFebMarAprMayJunJulAugSepOctNovDec&quot;)+2)/3
nYear=IIF(nMonth<MONTH(theDate), theYear+1, ;
IIF(nDay<=DAY(theDate) AND nMonth=MONTH(theDate), ;
theYear+1, theYear))
nDate=DATE(nYear, nMonth, nDay)
RETURN IIF(nDate>theDate AND nDate<GOMONTH(theDate,2), .T., .F.)
ENDFUNC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top