Display Year in aspx web page from a textbox date

Baiju EP 121 Reputation points
2022-12-29T11:33:45.103+00:00

I have 2 textboxes in aspx+vb+sql website

1st is datetxt.text and 2nd is yeartxt.text

in the date texttxt.text i have date captured from my sql table like this 12/24/2022 the date is (24th Dec 2022)

now i want to display year of the date in yeartxt.text (eg 2022)

ASP.NET Web Forms
ASP.NET Web Forms
A part of the ASP.NET web application framework that can be used to create ASP.NET web applications.
407 questions
{count} votes

Accepted answer
  1. Lan Huang-MSFT 9,201 Reputation points Microsoft Employee
    2022-12-30T02:46:05.3+00:00

    Hi @Baiju EP ,
    I think you can get the year through DateTime.Year Property directly based on the date from datetxt.text.
    https://learn.microsoft.com/en-us/dotnet/api/system.datetime.year?view=net-7.0

      yeartxt.Text = Convert.ToDateTime(datetxt.Text).Year.ToString()  
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    No comments

0 additional answers

Sort by: Most helpful