none
Assing System Date by Adding 2 years RRS feed

  • Question

  • hi,

    In Pharmacy some time forget to enter expiry date.  i need a code which assign the "Label.text" by system date adding two years. example

    (dd/mm/yyyy)(system date + 2Years)

    Expiry Date: 12/9/21

    Thanks.


    MUHAMMAD ANZAR E-mail : muhammadanzar@hotmail.com Mobile # :0092-3215096959

    Monday, December 9, 2019 5:45 PM

Answers

  • hi,

    In Pharmacy some time forget to enter expiry date.  i need a code which assign the "Label.text" by system date adding two years. example

    (dd/mm/yyyy)(system date + 2Years)

    Expiry Date: 12/9/21

    Thanks.


    MUHAMMAD ANZAR E-mail : muhammadanzar@hotmail.com Mobile # :0092-3215096959

    Hi

    Or,

        Label1.Text = Now.AddYears(2).ToString("MM/dd/yy")
    


    Regards Les, Livingston, Scotland

    • Marked as answer by muhammadanzar Monday, December 9, 2019 6:22 PM
    Monday, December 9, 2019 6:17 PM

All replies

  • You can set default values for records so when you insert a record you don't set those fields, the database does it for you. e.g. 

    CREATE TABLE [dbo].[AuditLog1](
    	[Id] [int] IDENTITY(1,1) NOT NULL,
    	[User] [nvarchar](max) NULL,
    	[Created] [datetime2](7) NULL,
    	[Epires] [datetime] NULL,
     CONSTRAINT [PK_AuditLog1] PRIMARY KEY CLUSTERED 
    (
    	[Id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
    
    ALTER TABLE [dbo].[AuditLog1] ADD  CONSTRAINT [DF_AuditLog1_Created]  DEFAULT (getdate()) FOR [Created]
    GO
    
    ALTER TABLE [dbo].[AuditLog1] ADD  CONSTRAINT [DF_AuditLog1_AnotherDate]  DEFAULT (dateadd(year,(2),getdate())) FOR [Epires]
    GO
    
    
    


    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

    Monday, December 9, 2019 6:11 PM
    Moderator
  • hi,

    In Pharmacy some time forget to enter expiry date.  i need a code which assign the "Label.text" by system date adding two years. example

    (dd/mm/yyyy)(system date + 2Years)

    Expiry Date: 12/9/21

    Thanks.


    MUHAMMAD ANZAR E-mail : muhammadanzar@hotmail.com Mobile # :0092-3215096959

    Hi

    Or,

        Label1.Text = Now.AddYears(2).ToString("MM/dd/yy")
    


    Regards Les, Livingston, Scotland

    • Marked as answer by muhammadanzar Monday, December 9, 2019 6:22 PM
    Monday, December 9, 2019 6:17 PM