I have a dateTimePicker created, and I only want to select month and year. So, I put the following code:
dateTimePicker2.Format = DateTimePickerFormat.Custom;
dateTimePicker2.CustomFormat = "MM yyyy";
dateTimePicker2.ShowUpDown = true;
Whenever I scroll with the arrow through the months, once it gets to February, the value is blank, instead of February.
I also tried customformats MMM and MMMM, but retain the same problem. I tried different years, but every year does not show February. I also tried to put a new datetimepicker, but continue having the same problem.
I can only select, without showUpDown = true, in the calendar, but still not with arrow up/down. It works without custom format, but I do not want to see the day, I only want to select month and year.
I'm using Visual Studio 2010 Ultimate (10.0.40219.1.SP1). .NET Framework 4.0.30319 SP1.
When the user select value by the up-down buttons or arrow keys, the DateTimePicker won't change the value of the element which is not included in its custom format.
I guess your dateTimePicker2 initially has the value of Now whose day of month is 29 or 30, hence the error on February.
I recommend you set 1 to dateTimePicker2.Value.Day beforehand.
Well, the problem really has to do with the fact that 02/29 will only be valid date on leap years. To prove this, scroll to 2012 and then scroll to 02. You'll have to implement code to catch an invalid value and either notify a user or move to 03/01.
DateTime has a method that lets you find out if a year is a leap year, so that you wouldn't have to jump through hoops: DateTime.IsLeapYear(year), where year is an int.
Here's a short list of leap years for your reference:
Leap Years (1800 - 2400)
1804 1808 1812 1816 1820 1824 1828 1832 1836 1840 1844 1848 1852 1856
1860 1864 1868 1872 1876 1880 1884 1888 1892 1896 1904 1908 1912 1916
1920 1924 1928 1932 1936 1940 1944 1948 1952 1956 1960 1964 1968 1972
1976 1980 1984 1988 1992 1996 2000 2004 2008 2012 2016 2020 2024 2028
2032 2036 2040 2044 2048 2052 2056 2060 2064 2068 2072 2076 2080 2084
2088 2092 2096 2104 2108 2112 2116 2120 2124 2128 2132 2136 2140 2144
2148 2152 2156 2160 2164 2168 2172 2176 2180 2184 2188 2192 2196 2204
2208 2212 2216 2220 2224 2228 2232 2236 2240 2244 2248 2252 2256 2260
2264 2268 2272 2276 2280 2284 2288 2292 2296 2304 2308 2312 2316 2320
2324 2328 2332 2336 2340 2344 2348 2352 2356 2360 2364 2368 2372 2376
2380 2384 2388 2392 2396 2400
If you think about it, you got really lucky with that bug. What are the odds that you'll be testing that control on 29, which is not a valid day for February of this year... You'll be able to fix it now and not when a user sends a report.
Related
We are storing only 4 digits in the database for the date of birth field . For example , if the date of birth is 05 Aug 1991 it gets stored as 050891
The issue here is when we do below :
Convert.ToDateTime("05/08/28") -> it produces 05 08 2029
Convert.ToDateTime("05/08/30") -> it produces 05 08 1930
Can some one please help me understand why first date year is considered as 2029 and in the second case it is 1930 instead of 2030 .
How .Net determines the year ?
Here is the .Net fiddle demonstrating the results
In your 1st .NET example, you wrote 05/08/29 so year 2029 is ok.
The 2-digit year is translated to a 4-digit year using Calendar.TwoDigitYearMax property.
I'm currently trying to display a datetime in the format of the local culture of the user.
As an example, an user from the US will see a date as 20 June 2020 05.50 PM where as an user from germany will see the date as 20 Juni 2020, 17:50.
My issue is, that e.g for the german case, I'd like to have a Uhr added at the end, so it will be 20 Juni 2020, 17:50 Uhr as explained in this related question.
Is there any way to achieve that in .NET as well? In theory I could just keep checking the culture and add Uhr if it's a german one, but I assume that there are other cultures as well with a similar suffix.
DateTime dtStart = new DateTime(2015,7,28);
LocalDate ldtStart = LocalDate.FromDateTime(dtStart);
DateTime dtEnd = new DateTime(2017, 2, 1);
LocalDate ldtEnd = LocalDate.FromDateTime(dtEnd);
Period period = Period.Between(ldtStart, ldtEnd, PeriodUnits.YearMonthDay);
Result for above:
period.Years -> 1
period.Months -> 6
period.Days -> 4
As you can see the difference i got from Noda Time library.
But i get different result for https://www.easycalculation.com/date-day/age-calculator.php
Result for above link:
1 years, 6 months, and 1 days
Start Date: 28th July 2015
End Date: 1st Feb 2017
Can someone please tell me that the result i got from noda time plugin is more accurate then the link I provided?
"More accurate" requires a specification of how you want to compute the difference. There's no single right answer here. As documented, Noda Time works element-wise. So if you add 1 year, 6 months and 4 days to 28th July 2015 you get:
Adding 1 year: 28th July 2016
Adding 6 months: 28th January 2017
Adding 4 days: 1st February 2017
The code used for the site is available on the site itself. It looks like that's taking a rather more naïve approach.
In particular, if you ask it how old someone born on January 31st 2017 is on February 1st 2017, they'll say they're -2 days old. I don't think that's right...
From 28th July 2015 to 1st August 2015 is 4 days and from 1st August 2015 to 1st Feb 2017 is exactly one and a half year.
NodaTime shows you correct information. You also could check with this link.
You could try to change in your link date from 28th July 2015 to 29th July 2015 or 30th July 2015 and you will see invalid input.
I am using SSRS 2012 and I have a field called months which return all the month from January to December .
But client wants that to be displayed as Jan , Feb , Mar,..,Dec first 3 letters of every month , I tried few works around in ssrs but my expression is not working. Can anyone help me with it. I cannot change into database as we want to display on Screen as full.
Option 1
You can get the MONTHNAME of a date by using
=MonthName(Month(Fields!myDate.Value))
And take the first 3 letters of this using LEFT
=Left(MonthName(Month(Fields!myDate.Value)), 3)
Option 1b
You can also use LEFT on any string
=Left(Fields!myString.Value, 3)
Option 2
Format the textbox or expression containing the date to have the format MMM
="MMM"
I am looking for a fiscal calendar class rather than having to roll my own.
So far I haven’t had much luck in finding something that suits me.
I am relatively new to the idea of a fiscal calendar and to programming for that matter.
The dates that my company uses for its fiscal reporting are strange to me, I can’t seem to make any sense of it and I am suspecting that the financial department uses tea leaves and chicken entrails to create the calendar. I have asked, several times but no answer.
Details :
Our fiscal year starts on July 1 every year. Our current year is named FY11.
The dates of our fiscal year are as follows:
Jul 30-Jun-10 to 27-Jul-10
Aug 28-Jul-10 to 28-Aug-10
Sep 29-Aug-10 to 27-Sep-10
Oct 28-Sep-10 to 26-Oct-10
Nov 27-Oct-10 to 27-Nov-10
Dec 28-Nov-10 to 28-Dec-10
Jan 29-Dec-10 to 26-Jan-11
Feb 27-Jan-11 to 23-Feb-11
Mar 24-Feb-11 to 28-Mar-11
Apr 29-Mar-11 to 26-Apr-11
May 27-Apr-11 to 28-May-11
Jun 29-May-11 to 29-Jun-11
The next year will be different . I have a number of years into the future.
Anyways, I have pretty much given up on trying to find example code that I could work from and I am asking this forum for any advice that you could give a beginner programmer on what approach you would take to creating a fiscal_calendar class.
I suspect that I will never find the true rational behind the financial departments financial calendar creation methodology and will be stuck with spreadsheets detailing the gregorian to fiscal comparison.
Thanks for any insight you can provide