Results 1 to 5 of 5

Thread: Check if today's date changes

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    32

    Check if today's date changes

    Could anyone give me some input on how to check if today's date changes?

    For example, in my program I have a label, which show's today's date, and when the time hits midnight, it's expected of the label to change to 19/07/2012.

    I need this procedure to be a Sub, which would be re-ran in a timer every hour, to check, since the program might be ran for multiple days at once.

    Thank you.

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Check if today's date changes

    Set the timer interval to whatever internal you want, store the previous date and do a comparison of the .Day property of the previous date to the current date.

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    32

    Re: Check if today's date changes

    Something like this, and placing it in the timer control?
    VB.NET Code:
    1. Public Sub checkDate()
    2.  
    3.         Dim thisDate As Date = Date.Today
    4.  
    5.         Dim nextDate As Date = thisDate.AddDays(1)
    6.  
    7.         Dim result As Integer = Date.Compare(thisDate, nextDate)
    8.  
    9.         If result = 0 Then
    10.             thisDate = nextDate
    11.         ElseIf result > 0 Then
    12.             thisDate = nextDate
    13.         End If
    14. End Sub

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Check if today's date changes

    why bother even checking? jsut have a time that fires off every couple of seconds, and display the current date... if it changes, it changes, if not, it just displays the same date until it does change....

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    32

    Re: Check if today's date changes

    Quote Originally Posted by techgnome View Post
    why bother even checking? jsut have a time that fires off every couple of seconds, and display the current date... if it changes, it changes, if not, it just displays the same date until it does change....

    -tg
    It's mainly due to the fact, that If I change the start date on a different form, the program won't change the date on the main form until the timer ticks to the next day.

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