Re: Calculating a time and date (counting down)

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Rick Rothstein (MVP - VB) wrote:

Below my name is a function I have posted in the past which takes a
single argument, number of seconds, and will return a formatted
String value giving the number of Years, Months, Weeks, Days, Hours,
Minutes and Seconds from Now until that number of seconds has
elapsed. Copy/Paste it into your project and then you can use it in
your Timer's Timer event like this...
Private Sub Timer1_Timer()
Label1.Caption = YMWDHMS(DateDiff("s", Now, DateSerial(2008, 7, 1)))
End Sub


Hey Rick, if you feel like doing some debugging, try

Private Sub Timer1_Timer()
Label1.Caption = YMWDHMS(597660)
End Sub

I get an oscillation between two ways of reporting that:

0 years, 0 months, 0 weeks, 6 days, 22 hours, 1 minute, 0 seconds
0 years, 0 months, 0 weeks, 6 days, 22 hours, 0 minutes, 60 seconds

It has to do with winding up with 1.00000000000016 minutes, which leads to 1
min. 0 sec, or with 0.999999999999943 minutes, which gives 0 min. 60 secs.

I'm sure there are other SecondsIn values that could produce the same result.


.



Relevant Pages

  • Re: Style question - lengthy nested If-Thens
    ... Monte Hansen - MVP VB ... "Rick Rothstein" wrote in message ... >> that calling a Private Sub? ... >> half-dozen GoSub blocks. ...
    (microsoft.public.vb.general.discussion)
  • Re: Transfer Multiple-Font Cells ??
    ... "Rick Rothstein" wrote: ... Private Sub Worksheet_Change ... Rick (MVP - Excel) ... Numerous cells in columns A and B on a w/s have a combination ...
    (microsoft.public.excel.worksheet.functions)
  • Re: time format
    ... "Rick Rothstein" wrote: ... Private Sub Worksheet_Change(ByVal Target As Range) ... I enter in a cell 5a it should automatically format it to 5:00 AM ...
    (microsoft.public.excel.misc)
  • Re: conditional formatting
    ... "Rick Rothstein" wrote: ... Private Sub Worksheet_Change(ByVal Target As Range) ... Ctrl+C followed by Ctrl+V (keyboard shortcuts for copy/paste for Column O) ...
    (microsoft.public.excel.programming)
  • Re: Calculating a time and date (counting down)
    ... Rick Rothstein (MVP - VB) wrote: ... Blame this on Bobzter100:) ... Private Sub Timer1_Timer ...
    (microsoft.public.vb.general.discussion)