Countdown to a date/time 
Author Message
 Countdown to a date/time

Hello,
    Okay, here's the story.  My wife is expecting a baby in June.  I want to
write a "countdown clock" much like the ones you see all over the web (in
JavaScript) that countdown to this date.  The problem with the JavaScript
countdown clocks is that the ones I've seen only count the number of days,
minutes, seconds to the date.
    What I am trying to do is count the years, months, days, hours, minutes,
seconds.  Basically, it will countdown to the date/time and then once the
date/time has arrived, it will start counting up.

    I have found no good way of counting the number of years, months, days,
hours, minutes, seconds to or since a specific date/time.

Any help is greatly appreciated.

Scott A Carle
Proud to be 'upcoming' father



Sun, 01 Jul 2001 03:00:00 GMT  
 Countdown to a date/time

Quote:

> Hello,
>     Okay, here's the story.  My wife is expecting a baby in June.  I want to
> write a "countdown clock" much like the ones you see all over the web (in
> JavaScript) that countdown to this date.  The problem with the JavaScript
> countdown clocks is that the ones I've seen only count the number of days,
> minutes, seconds to the date.
>     What I am trying to do is count the years, months, days, hours, minutes,
> seconds.  Basically, it will countdown to the date/time and then once the
> date/time has arrived, it will start counting up.

>     I have found no good way of counting the number of years, months, days,
> hours, minutes, seconds to or since a specific date/time.

> Any help is greatly appreciated.

> Scott A Carle
> Proud to be 'upcoming' father


i'm a c++ programmer that had to learn vb for my current job. as a learning
exercise i wrote a small app that does a y2k countdown. it displays 352 -
11:58:27 you could easily expand on the logic to do what you want to do. if you
want it, email me and i'll send you the vb project.


Sun, 01 Jul 2001 03:00:00 GMT  
 Countdown to a date/time
Use the DateDiff function. It will tell you all you need to know.
Put the calls to DataDiff in a timer event to be called once a second or
once a minute.

Regards,
Simon Jones
MillStream Design
Independent IT Consultants



Quote:
>    Okay, here's the story.  My wife is expecting a baby in June.  I want
to
>write a "countdown clock" much like the ones you see all over the web (in
>JavaScript) that countdown to this date.  The problem with the JavaScript
>countdown clocks is that the ones I've seen only count the number of days,
>minutes, seconds to the date.
>    What I am trying to do is count the years, months, days, hours,
minutes,
>seconds.  Basically, it will countdown to the date/time and then once the
>date/time has arrived, it will start counting up.

>    I have found no good way of counting the number of years, months, days,
>hours, minutes, seconds to or since a specific date/time.



Mon, 02 Jul 2001 03:00:00 GMT  
 Countdown to a date/time
Datediff doesn't have a "relative" date property does it?
From all I know about DateDiff, all it can do is tell me how many years
until a date, OR how many months until a date, OR how many days until a
date, OR how many hours, etc. etc.

I am trying to work something out with DateDiff tho.
Find the number of years (though DateDiff isn't exactly good at that
(12/31/1998 and 1/1/1999 is one year difference with Datediff("yyyy",
12/31/1998, 1/1/1999), but anyway).
Then increment my date field to that year, then do the months, so on and so
on, and hopefully this will work.

PowerBuilder has a "relative date" function.  Give me the relative date
between these two dates and it returns years, months, days, hours, minutes,
seconds between the two.

Anyway, thanks for the suggestions.
I've been programming VB for about 3 years now. Just never had much luck
with DateDiff.

Scott

Quote:

>Use the DateDiff function. It will tell you all you need to know.
>Put the calls to DataDiff in a timer event to be called once a second or
>once a minute.

>Regards,
>Simon Jones
>MillStream Design
>Independent IT Consultants



>>    Okay, here's the story.  My wife is expecting a baby in June.  I want
>to
>>write a "countdown clock" much like the ones you see all over the web (in
>>JavaScript) that countdown to this date.  The problem with the JavaScript
>>countdown clocks is that the ones I've seen only count the number of days,
>>minutes, seconds to the date.
>>    What I am trying to do is count the years, months, days, hours,
>minutes,
>>seconds.  Basically, it will countdown to the date/time and then once the
>>date/time has arrived, it will start counting up.

>>    I have found no good way of counting the number of years, months,
days,
>>hours, minutes, seconds to or since a specific date/time.



Mon, 02 Jul 2001 03:00:00 GMT  
 Countdown to a date/time
This is simple arithmetic.

Take the number of days between the two dates, as reported by DateDiff. Using integer division "\", divide the number of days by 365 to get the number of years. Take the remainder of this division (Mod) and divide that by 30 to get the number of months left over. Take the remainder of this division (Mod again) and that's the number of days left over.

400 \ 365 = 1 year
400 Mod 365 = 35 days remaining
35 \ 30 = 1 month
35 Mod 30 = 5 days

400 days = 1 year 1 month and 5 days

Any calculation like this can only be approximate as months and years vary in length. 365 and 30 are the nearest integers to the mean values. If you want to go to hours minutes and seconds then ask DateDiff for seconds and keep dividing & Moding.

Regards,
Simon Jones
MillStream Design
Independent IT Consultants


Quote:
>Datediff doesn't have a "relative" date property does it?
>From all I know about DateDiff, all it can do is tell me how many years
>until a date, OR how many months until a date, OR how many days until a
>date, OR how many hours, etc. etc.

>I am trying to work something out with DateDiff tho.
>Find the number of years (though DateDiff isn't exactly good at that
>(12/31/1998 and 1/1/1999 is one year difference with Datediff("yyyy",
>12/31/1998, 1/1/1999), but anyway).
>Then increment my date field to that year, then do the months, so on and so
>on, and hopefully this will work.

>PowerBuilder has a "relative date" function.  Give me the relative date
>between these two dates and it returns years, months, days, hours, minutes,
>seconds between the two.

>Anyway, thanks for the suggestions.
>I've been programming VB for about 3 years now. Just never had much luck
>with DateDiff.

>Scott



Tue, 03 Jul 2001 03:00:00 GMT  
 Countdown to a date/time
Ah yes, I remember now: "30 days hath September, April, June and November;
all the rest have 30, except February, which has 30."

Here's what I did to display how old my son is on a web page, using
JavaScript, maybe somebody will find it useful (or not):

<script language="JavaScript">
function howOld(birthdayString) {
    var birthday, today, delta, years, month, string;

    birthday = new Date(birthdayString);
    today = new Date();
    today.setHours(23);
    today.setMinutes(59);
    today.setSeconds(59);
    delta = new Date();
    delta.setTime(today.getTime() - birthday.getTime());
    years = delta.getYear() - 70;
    months = delta.getMonth();

    string = '';
    if (years > 0) {
      string = string + years + ' year';
      if (years > 1) string = string + 's';
        if (months > 0) string = string + ' ';
    }
    if (months > 0) {
        string = string + months + ' month';
        if (months > 1) string = string + 's';
    }
    return string;

Quote:
}

</script>

Then your HTML can do something like:

<html>
<body>
My son is <script>howOld("January 16, 1998");</script> old today.
</body>
</html>

Brad Horstkotte

----------------

This is simple arithmetic.

Take the number of days between the two dates, as reported by DateDiff.
Using integer division "\", divide the number of days by 365 to get the
number of years. Take the remainder of this division (Mod) and divide that
by 30 to get the number of months left over. Take the remainder of this
division (Mod again) and that's the number of days left over.

400 \ 365 = 1 year
400 Mod 365 = 35 days remaining
35 \ 30 = 1 month
35 Mod 30 = 5 days

400 days = 1 year 1 month and 5 days

Any calculation like this can only be approximate as months and years vary
in length. 365 and 30 are the nearest integers to the mean values. If you
want to go to hours minutes and seconds then ask DateDiff for seconds and
keep dividing & Moding.

Regards,
Simon Jones
MillStream Design
Independent IT Consultants



Quote:
>Datediff doesn't have a "relative" date property does it?
>From all I know about DateDiff, all it can do is tell me how many years
>until a date, OR how many months until a date, OR how many days until a
>date, OR how many hours, etc. etc.

>I am trying to work something out with DateDiff tho.
>Find the number of years (though DateDiff isn't exactly good at that
>(12/31/1998 and 1/1/1999 is one year difference with Datediff("yyyy",
>12/31/1998, 1/1/1999), but anyway).
>Then increment my date field to that year, then do the months, so on and so
>on, and hopefully this will work.

>PowerBuilder has a "relative date" function.  Give me the relative date
>between these two dates and it returns years, months, days, hours, minutes,
>seconds between the two.

>Anyway, thanks for the suggestions.
>I've been programming VB for about 3 years now. Just never had much luck
>with DateDiff.

>Scott



Fri, 06 Jul 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Countdown to a date/time

2. Countdown to a date/time

3. Date/Time Countdown

4. Compare date in form with date/time in form with date/time in database

5. VB3:Date Countdown Function

6. Matching system date/time with field date/time

7. combining a time and a date to one Date/Time value

8. start date/time, end date/time problem

9. How to subtract a date-time from a date-time

10. ADO with Access Date/Time field not storing the time, just the date

11. Converting %date% %time% to VB Time/Date

12. Date/Time to date

 

 
Powered by phpBB® Forum Software