C# set April 1st as start of year

calendar c# code
c# julian calendar example
c# calendar control winforms
c# day of year

I'm currently working on an app to add data to a SQL table.

One of the fields in the table is for financial month as YYYYMM (e.g. 201805 for August 2018). I need to set this automatically when the row is added as we can't rely on the users to input the correct format.

Is there any way to set DateTime to start the year on 1st April (first day of financial year), or am I going to have to code my way around the issue.


Thanks for all the answers, they did help me solve the problem.

I eventually went with a really simple solution that I probably should have thought of in the first place.

string period = DateTime.Now.AddMonths(-3).ToString("yyyyMM");

Annual Report of the City Officers, Is there any way to set DateTime to start the year on 1st April (first day of financial year), or am I going to have to code my way around the issue. Currently I am setting the first date pickers default date to Today()-21 and the second to Today()+7, so it shows me kind of a rolling 30 days but not really a month view where it is for the particular month where since today is June 12, it is setting the default date in date picker one to June 1 and the default date in date picker 2 to June 30.


What you want is a varchar (or nvarchar) column, with a default that looks something like:

     (format(dateadd(month,(-4),getdate()),''yyyyMM'',''en-US'')) 

But, it appears that SQL Server doesn't like having a default with three functions nested inside each other (two, it seems ok with, but it burps on three). Instead, you can have a Date type column with a default of:

     (dateadd(month,(-4),getdate()))

That seems to work, but it's a date 4 months ago. Then just format it correctly whenever you display it.

Calendar.GetYear(DateTime) Method (System.Globalization , 1st size Metropolitan . 1st size 150 850 200 5 Engine No. 3. v tart ladder nozzle—Deluge set. | * Pay-Roll April 1st, 1908, to July 1st, 1909. 1908. April # | | where xxxx is any year. This table shows the return value for the week and weekday datepart for '2007-04-21 ' for each SET DATEFIRST argument. January 1, 2007 falls on a Monday. April 21, 2007 falls on a Saturday. For U.S. English, SET DATEFIRST 7 -- ( Sunday ) serves as the default.


You could use the following piece of code to get the start of your desired financial year.

    var year = DateTime.Now.Year;
    DateTime firstDay;
    if(DateTime.Now.Month <= 4)
       firstDay = new DateTime(year-1, 4, 1);
    else
       firstDay = new DateTime(year, 4, 1);

There doesn't seem to be a way to do this automatically, but it looks simple enough.

Code of Federal Regulations: 1985-1999, When overridden in a derived class, returns the year in the specified . April 3, 2002 of the Gregorian calendar: Era: 1 Year: 2002 Month: 4 DayOfYear: 93  Except that would use the same financial year for March 1st and May 1st, which isn't what the OP would want, as far as I can tell. – Jon Skeet Aug 17 '18 at 10:31 add a comment |


JulianCalendar.GetDayOfYear(DateTime) Method (System , The agreement shall set forth the total amount of the deficiency distribution to be A purposes of the Internal Revenue C# such charge is considered interest (ii) of X's taxable years beginning after 1972 and before April 1, 1976 Charge to be  SET DATEFIRST 7; SELECT CAST('1999-1-1' AS datetime2) AS SelectDate ,DATEPART(dw, '1999-1-1') AS DayOfWeek; -- January 1, 1999 is a Friday. Because the U.S. English default -- specifies Sunday as the first day of the week, DATEPART of 1999-1-1 -- (Friday) yields a value of 6, because Friday is the sixth day of the -- week when you start with


Calendar Class (System.Globalization), C# Copy. public override int GetDayOfYear (DateTime time); override this. An integer from 1 to 366 that represents the day of the year in time . public class SamplesJulianCalendar { public static void Main() { // Sets a DateTime to April 3, 2002 For example, GetDayOfYear for the first day of the first month returns 1, and  Here’s how to set the start of the fiscal year. On the File tab, click Options. If you’re using Project 2007, click Options on the Tools menu. On the Project Options dialog, click Schedule, and then find the fiscal year drop-down list. For Project 2007, on the Options dialog box, click the Calendar tab.


Official Journal of the Proceedings of the Senate of the State of , C# Copy. using System; using System.Globalization; public class April 3, 2002 of the Gregorian calendar: Era: 1 Year: 2002 Month: 4 DayOfYear: 93  Enter a week number to locate the week on a calendar; or enter any date to see in which week number it falls. Count Days Add Days Workdays Add Workdays Weekday Week № Need some help? Date Calculators. Time and Date Duration – Calculate duration, with both date and time included. Date Calculator – Add or subtract days, months, years.