Results 1 to 8 of 8

Thread: [RESOLVED] A date variable refuses to get today

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    384

    Resolved [RESOLVED] A date variable refuses to get today

    Hi all o7. How is the correct way to update a date variable?

    Following code does a cycle every seconds (lots of things happen here which are commented for now) in 24th hour of the day, yesterday ≠ today will happen and calibration/registration check [at its simplest way] will take place. After checking and analyzing things (which is not the case) yesterday variable should become today to avoiding it to happen next seconds for that day. But it is not happening. The debug msgbox (it's not necessary for final app) will always indicate "01/01/0001" obviously "yesterday" will not follow the term "Today".

    Code:
    Public Class FORMTEST
        Dim YESTERDAY As String
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        'COMMENTED CODE
            If YESTERDAY IsNot Today.ToShortDateString Then
                MsgBox(YESTERDAY & vbNewLine & Today.ToShortDateString)
                'THINGS ALSO HAPPEN HERE IN THE FUTURE
                YESTERDAY = Today.ToShortDateString
            End If
        End Sub
    End Class
    Additional question: "Today" is present in Date.Today, DateAndTime.Today and DateAndTime.Today with different accent colors. What are their differences?

    What I've tried:
    - Me.Invoke(Sub() / End Sub) Not sure why I did that but thought this is the matter of graphics update (codes in prior)
    - Commenting all prior codes = same result.
    - Tried both String type and date actual format = same result. Code is in string type I assume string is always simpler.
    - Tried YESTERDAY = New Date(Today).ToShortDateString seems the dictation is faulty.
    Last edited by pourkascheff; Oct 14th, 2023 at 03:15 AM.

Tags for this Thread

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