Using System;
Namespace My.utils {
<summary>
Date Operations Common tools
</summary>
public class Dateutils {
Public Dateutils () {
}
<summary>
Year difference of comparison date
</summary>
<param name= "Start" > Start date </param>
<returns> year difference from current date </returns>
public static int Diffyear (string start) {
Return Diffyear (Convert.todatetime (start));
}
<summary>
Year difference of comparison date
</summary>
<param name= "Start" > Start date </param>
<param name= "End" > End Date </param>
<returns> Year Difference </returns>
public static int Diffyear (string start, String end) {
Return Diffyear (Convert.todatetime (start), Convert.todatetime (end));
}
<summary>
Year difference of comparison date
</summary>
<param name= "Start" > Start date </param>
<returns> year difference from current date </returns>
public static int Diffyear (DateTime start) {
Return (Diffyear (start, DateTime.Now));
}
<summary>
Compare year differences of two dates
</summary>
<param name= "Start" > Start date </param>
<param name= "End" > End Date </param>
<returns> Year Difference </returns>
public static int Diffyear (datetime start, DateTime end) {
Return (end. Year-start. year);
}
<summary>
Format date of day (YYYY-MM-DD)
</summary>
<returns> formatted date string </returns>
public static string DateFormat () {
return DateFormat (DateTime.Now);
}
<summary>
Formatted Date (YYYY-MM-DD)
</summary>
<param name= "Date" > Date to be formatted </param>
<returns> formatted date string </returns>
public static string DateFormat (string date) {
return DateFormat (Convert.todatetime (date));
}
<summary>
Formatted date
</summary>
<param name= "Date" > Date to be formatted </param>
<param name= "format" > Formatting strings </param>
<returns> formatted date string </returns>
public static string DateFormat (string date, string format) {
return DateFormat (Convert.todatetime (date), format);
}
<summary>
Formatted Date (YYYY-MM-DD)
</summary>
<param name= "Date" > Date to be formatted </param>
<returns> formatted date string </returns>
public static string DateFormat (DateTime date) {
return DateFormat (date, "Yyyy-mm-dd");
}
<summary>
Formatted date
</summary>
<param name= "Date" > Date to be formatted </param>
<param name= "format" > Formatting strings </param>
<returns> formatted date string </returns>
public static string DateFormat (DateTime date, string format) {
Return date. ToString (format);
}
<summary>
Format Date Time
</summary>
<param name= "datetime" > Date time to be formatted </param>
<returns> Date Time string after formatting </returns>
public static string DateTimeFormat (DateTime datetime) {
Return DateTimeFormat (DateTime, "Yyyy-mm-dd hh:mm");
}
<summary>
Format Date Time
</summary>
<param name= "datetime" > Date time to be formatted </param>
<param name= "format" > Formatting strings </param>
<returns> Date Time string after formatting </returns>
public static string DateTimeFormat (DateTime datetime, string format) {
return datetime. ToString (format);
}
}
}