Display Year in aspx web page from a textbox date

Baiju EP 141 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
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,249 questions
{count} votes

Accepted answer
  1. Lan Huang-MSFT 25,471 Reputation points Microsoft Vendor
    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful