Simple, Dynamic Copyright Date with asp.Net and C#

Although copyright dates on websites are typically only changed one time a year, there’s an easy solution to not have to bat an eye when that new year rolls around. Using an ASP.Net Literal control, and some code-behind in the page load event (C#), we can grab the date from the server time and spit out the year; this eliminates the need for a developer to jump into master pages, controls, etc down the road and have to change these.

Add to your Master page, Control, etc. a simple literal control:

<asp:Literal ID="CopyYear" runat="server" />

And then the Code

protected void Page_Load(object sender, EventArgs e)
 DateTime copyDateTime = DateTime.Now;
 string year = copyDateTime.Year.ToString();
 CopyYear.Text = year;
Posted in, C-Sharp, C#
  • Thanks for the post. Came in really handy. I’m learning some ASP.NET and c#, and this is exactly what I was looking for. I’m very good at frontend code, and trying to learn more about how to tie the backend in with the frontend. Do you have any references that would be helpful with ASP.NET and c#?

    Thanks again!