You can get Current day, month, and year using this class
public class MY_Date
{
/// <summary>
/// Current Month
/// </summary>
public static string CurMonth = GetCurrentMonth();
/// <summary>
/// Current Year
/// </summary>
public static string CurYear =GetCurrentYear();
/// Current Month
/// </summary>
public static DateTime Yesterday = GetYesterday();
/// <summary>
/// Current Year
/// </summary>
public static DateTime Tomorrow = GetTomorrow();
private static string GetCurrentYear()
{
DateTime dt = DateTime.Now;
return dt.Year.ToString();
}
private static string GetCurrentMonth()
{
DateTime dt = DateTime.Now;
return dt.Month.ToString();
}
/// <summary>
/// last day of the year for today.
/// </summary>
static DateTime LastDayOfYear()
{
return LastDayOfYear(DateTime.Today);
}
/// <summary>
/// last day of the year for the selected day's year.
/// </summary>
static DateTime LastDayOfYear(DateTime d)
{
// 1
// Get first of next year
DateTime n = new DateTime(d.Year + 1, 1, 1);
// 2
// Subtract 1 from it
return n.AddDays(-1);
}
/// <summary>
/// Gets the first day of the current year.
/// </summary>
static DateTime FirstDayOfYear()
{
return FirstDayOfYear(DateTime.Today);
}
/// <summary>
/// Finds the first day of year of the specified day.
/// </summary>
static DateTime FirstDayOfYear(DateTime y)
{
return new DateTime(y.Year, 1, 1);
}
/// <summary>
/// Gets the next day, tomorrow.
/// </summary>
private static DateTime GetTomorrow()
{
return DateTime.Today.AddDays(1);
}
/// <summary>
/// Gets the previous day to the current day.
/// </summary>
private static DateTime GetYesterday()
{
// Add -1 to now
return DateTime.Today.AddDays(-1);
}
}






Precise info...
ReplyDelete