Results 1 to 2 of 2

Thread: count down timer till end of the month

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    9

    count down timer till end of the month

    How to create a timer that start from today date and count down till the end of the month.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: count down timer till end of the month

    First, it's important to understand that a Timer doesn't count up or down or anything in between. All a Timer does is raise a Tick event at a regular interval. What you do in the Tick event handler is up to you. You can update a Label with the current time or the time remaining until a specific time or whatever.

    So, first you need to get a Date to represent the end of the month:
    vb.net Code:
    1. Dim todays As Date = Date.Today
    2. Dim startOfMonth As New Date(today.Year, Today.Month, 1)
    3. Dim endOfMonth As Date = startOfMonth.AddMonths(1)
    You'll need to store that result in a member variable so that you can use it repeatedly. To calculate the amount of time remaining until that target, you simply subtract the current date and time from it:
    vb.net Code:
    1. Dim timeRemaining As TimeSpan = endOfMonth - Date.Now
    That TimeSpan has properties for days, hours, minutes, etc, so you can create a string to display in a Label or whatever.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width