Created
November 17, 2022 20:03
-
-
Save digitaldirk/955f9e19dde6983359430d482c10aafb to your computer and use it in GitHub Desktop.
C# copyright string helper method that takes a DateTime and optionally a string to output something like: © 2010-2022 Company
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Gets a copyright string in the form of: "© 2022 CompanyName" or like "© 2016-2022 Person" | |
/// </summary> | |
/// <param name="CopyrightStart">DateTime that represents the start date of copyright - only the year is used.</param> | |
/// <param name="CopyrightHolder">Optional string of copyright holder - empty string is default</param> | |
/// <returns>Copyright string</returns> | |
public static string GetCopyrightString(DateTime CopyrightStart, string CopyrightHolder = "") | |
{ | |
string CopyrightString = string.Empty; | |
// If Copyright year is greater or equal to the current year, only use copyright year e.g. 2022 | |
if (CopyrightStart.Year >= DateTime.Now.Year) | |
{ | |
CopyrightString = "© " + CopyrightStart.Year + " " + CopyrightHolder; | |
} | |
// If Copyright year is less than the current year, use range of copyright year to current year e.g. 2021-2022 | |
else if (CopyrightStart.Year < DateTime.Now.Year) | |
{ | |
CopyrightString = "© " + CopyrightStart.Year + "-" + DateTime.Now.Year + " " + CopyrightHolder; | |
} | |
return CopyrightString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment