First and Last Day of the Month written in C# - VisualCron - Forum

Community forum

shahsaud
2022-08-04T14:43:32Z
For Visual Cron

Below C# code returns true or false if today is first day of the month or not.

using System;

public class FirstDayMonth
{
public static bool FirstDayOfMonth()
{
DateTime now = DateTime.Now;


var firstDay = new DateTime(now.Year, now.Month, 1);

if (now.Day == firstDay.Day)

return true ;
else
return false ;
}
}





Last working day:

using System;

public class LastDayMonth
{
public static bool LastDayOfMonth()
{
DateTime now = DateTime.Now;

int daysInMonth = DateTime.DaysInMonth (now.Year, now.Month);

var lastDay = new DateTime(now.Year, now.Month, daysInMonth);

if (now.Day == lastDay.Day)

return true ;
else
return false ;
}
}


Scroll to Top