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

Diffrent Date calculation

Status
Not open for further replies.

annupam2003

Programmer
Sep 27, 2012
1
FUNCTION Date_diff(old_date as String, new_date as String) as String
dd2=CTOD(new_date)
dd1=CTOD(old_date)
*!* dd2={02/03/2012}
*!* dd1={01/01/2012}
result=dd2-dd1
IF result < 0
MESSAGEBOX("Check the Date")
return
endif

xxYear=0
xxMonth=0
xxDay=0
j=0
k=result
z=0

IF result > 365
FOR I=0 TO RESULT
IF j = 365
xxYear=xxYear+1
j=0
IF k<365
EXIT
endif
ENDIF
j=j+1
k=k-1
NEXT
ENDIF
*SET STEP ON
l=0
j=0
l=k

IF (k < 365 OR result < 365) AND k > 30
FOR i=0 TO k
IF j=30
xxMonth=xxMonth+1
j=0
IF l < 30
exit
endif
ENDIF
j=j+1
l=l-1
next
ENDIF

IF INLIST(MONTH(dd2),1,3,5,7,8,10,12)
xxDay=l
ELSE
xxDay=l-1
ENDIF
RETURN IIF(xxYear >0,STR(xxYear)+"Y ","0Y ")+IIF(xxMonth >0 ,STR(xxMonth)+"M ","0M ")+IIF(xxDay >0,STR(XXDAY)+"D","0D ")
ENDFUNC
 
What is your question?

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
If you have a question, you should ask it.

If that is meant as a helpful tip, you should change the thread type to it, but it would be more helpful, if you described the function and format it with VFPs beautify.

I just tried it out, and it gives me a wrong result with the dates 24th September 2012 and 27th September 2012:

? Date_diff(DTOC(DATE(2012,9,24)),DTOC(DATE(2012,9,27)))
Returns "0Y 0M 2D", while it should return "0Y 0M 3D".

I wouldn't even dive into that logic and rewrite that. Useful functions are YEAR(), MONTH(), DAY() and GOMONTH().

Bye, Olaf.
 
As noted above, please either ask your question, or explain what this is all about.

We can't read your mind.

mmerlinn


Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond
 
One other point. If this was meant as a tip, it seems unnecessary. To find out the difference in days between two dates, just subtract one from the other.

Tamar
 
Well, it computes a diff in years, months and days, Tamar. It may be used to display a countdown to a conference, for example, or to any other occasion.

Bye, Olaf.
 
Ah, that's what I get for not reading all the code. I saw the name and a couple of CTOD() calls, and jumped to a conclusion.

Tamar
 
still, what is the world is the point here?

a quesiton?
a bug?
a tip?
a virus?


Ali Koumaiha
TeknoSoft Inc.
Michigan
 
yup

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
** Playing Jeopardy music

Ali Koumaiha
TeknoSoft Inc.
Michigan
 
Since he posted the same code in another forum, I'm pretty sure he was sharing it.

Tamar
 
Well, if that's the case, it was nice of him.

would be nice to say "tip"

Ali Koumaiha
TeknoSoft Inc.
Michigan
 
really?

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Could be a girl?

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
>Hadn't we better write this thread off?

If you want a serious decision about this: I don't know.

It's not inappropriate, but it's surely also not worth keeping for the undocumented nature of the code and it's error I already showed.

If annupam2003 wants to contribute and thank for what he got from here, that gesture is friendly and accepted, thank you annupam. One can get the idea and perhaps turn it into something useful. If there is a language barrier aside of the FoxPro language, it's even comprehensable the code isn't commented and there is no further comment written besides the code itself.

I have the urge to come up with something working based on the functions I mentioned, but it has limited value to anybody and I can do more valuable answering or mentoring, though looking back I also have mended worse code and our company is just currently facing code from an in house developer leaving a customer, that is even harder to get into, merely because of the quantity of code to review. It took months already and it will rather lead to a reimplementation.

But that's already distracting from this thread.

No harm is taken here, hopefully annupam also understands the little jokes we made here, otherwise I'm back to "I don't know". Maybe it's the best to just ignore this or delete it. But only without any penalty to annupam, there is no bad intention about this.

Bye, Olaf.
 
After joining Tek-Tips Forums on September 27, 2012, annupam2003 has logged in 1 time.
Their last login was on Thursday, September 27, 2012.
They have started 1 threads, posted 0 replies, and written 0 FAQs.


As has been indicated, no harm done, but also not much gained through having to make multiple guesses as to the intent of the posting.

I think that all of us would have appreciated seeing annupam2003 be interested enough to come back and offer some explanation - possible language barrier or not.

If someone wants to eliminate this enigmatic posting, they need only Red Flag it at the top level and in the request notes, just indicate that it is not a true 'Red Flag', but a request to eliminate 'Dead Wood' from the forum.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top