locked
Do something if date is expired RRS feed

  • Question


  • I want to do something (eg. make the button disabled) if the particular date, determined in advance in code, is expired.
    I need such a piece of code that should be working regardless of the date format applied locally.
    (I am using Visual Studio 2015)


    Thanks in advance.

    • Edited by Zghr Wednesday, October 28, 2020 4:14 PM
    Wednesday, October 28, 2020 3:46 PM

All replies

  • Hi

    You can compare the stored date with Now.Date abd find if has expired.


    Regards Les, Livingston, Scotland

    • Proposed as answer by Castorix31 Wednesday, October 28, 2020 4:14 PM
    Wednesday, October 28, 2020 3:52 PM
  • Hello,

    For enable/disable

    Public Class Form1
        Private NotPastThisDate As Date = #10/30/2020#
        Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
            ExecuteButton.Enabled = Not #1-10-2020# >= NotPastThisDate
        End Sub
    End Class
    
    For different date format, DateTime.ParseExact.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, October 28, 2020 4:39 PM
  • Hi Zghr,

    How is the question going? If your question has been answered then please click the "Mark as Answer" Link at the bottom of the correct post(s), so that it will help other members to find the solution quickly if they face a similar issue.

    Besides, if you need further assistance, please let us know.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 30, 2020 2:02 AM