CountDown with months and years!

J

jonesfranckandi

Hi everyone,

I have managed to create a module that calculate (countdown) the number
of remain time form the end date. this is in days, Hours, Minutes and
seconds. But I want to extend it to years and month. I can do the year
bit but the month's one is hard because each month may have different
numbers of days ( february:28 or 29 days, some have 30 days and others
31 days.). I tried to continue with Mod with a fixed value but it is
not what I expected. I nedd help.Can anyone help me Please!!!!

Your help will be much appreciated. The code I have so far is below.

Thanks in advance.

Public Function CountDown(EndTime as Variant) as String
Dim lTemp as long
Dim D as Integer, H as Integer, M as Integer, S as Integer
If Not IsDate(EndTime) then Exit Function
lTemp = DateDiff("s", Now, EndTime)
S = lTemp Mod 60
lTemp = lTemp \ 60
M = lTemp Mod 60
lTemp = lTemp \ 60
H = lTemp Mod 24
D = lTemp \ 24
CountDown = D & " Day(s): " & H & " Hour(s):" _
& M & " Minute(s): " & S & " Second(s)"
End Function
 
M

Mesa

I have just the answer for you. The only draw is that it does not
update a field because it just displays the days in a textbox to no
control source. Just place this code in the "Control Source" on
properties. Its real simple...

Replace the "Control Date" with your countdown date.

In days

=DateDiff("d",[Control
Date],Now())+Int(Format(Now(),"mmdd")<Format([Control Date],"mmdd"))

In months

=DateDiff("m",[Control
Date],Now())+Fix(Format(Now(),"mmdd")<Format([Control Date],"mmdd"))

In years

=DateDiff("yyyy",[Control
Date],Now())+Int(Format(Now(),"yyyy")<Format([Control Date],"yyyy"))
 
J

jonesfranckandi

Graham Many Thanks!

Thank you for giving me the link. But I saw your coding and it was kind
of very long. In fact, I wanted something not too fancy. I managed to
figure out how to do it with months and years using if statement,
select case and MOD. but I saved your web address in my files for
future reference. thank you again. Come to think of it. Did you do this
module all by yourself? If so, then you are a true a genuis. Maybe the
finest access programmer I have seen. Whao that was top class!. Very
ingenous indeed. You are something special!.
Many Thanks!!!!!!!!!!
 
G

Graham R Seach

<<...and it was kind of very long.>>
Sometimes doing what you want requires a bit of code.

....<<do this module all by yourself?>>
No, MVP Doug Steele and I worked on it together.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
J

jonesfranckandi

Hi, Graham,

ok, I understand Then. But still you are good though.
Many Thanks Again!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top