How to trim Characters in ssrs - c#

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"

Related

C# Datatable sorting date DESC

I am displaying a list of items in a data grid binded to dt_pdc. The DueDate column shows the date of the cheque, as day, month and year. When i'm sorting using descending, it does the following:
Date List & Order:
1---4/18/2020
2---4/2/2020
3---4/22/2020
When the day's first digit is less than another day's first digit, it is being sorted first, in the example, 18 april is coming before 2 april, however 22 april comes after 2 april.
Is there anything that i can fix in the sorting view, or do i have to write it in the DB as 02 instead of 2.
dt_pdc.Columns.Add("ID");
dt_pdc.Columns.Add("ChequeNumber");
dt_pdc.Columns.Add("DueDate");
dt_pdc.Columns.Add("Amount");
dt_pdc.Merge(Database.Accounts.Cheques.getPDCChequesSearch(dt_pdc));
dt_pdc.DefaultView.Sort = "DueDate ASC";
or do i have to write it in the DB as 02
no, that's just compounding the error (wait until you get an urgent support call on new year's day if you don't believe me); basically: stop storing dates as strings; store them as dates - i.e. DateTime; then everything will work correctly. If you absolutely must use string for some reason (and it would need to be a good reason), consider using ISO8601 format, i.e. store it as "2020-04-02"; this is then sortable naturally as a string, plus it is unambiguous (there is no question as to whether this is the 2nd of April or the 4th of February).

MM-dd-yyyy to Julian yyddd

I am trying to get a label to display the Julian date in a specific format. The last two digits of the year then the day in the year, so for example January 1 2021 would be 210001. I am having difficulty getting it to display both of these values attached and making the day slot have 3 values instead of 2.
This is what I have.
This just gives the day of the year but still not as a 3 digit day so it shows 1 as 1 instead of 001 which is my goal
Any help would be appreciated! :)
Unfortunately the date time formats do not include anything for day of the year so you'll have to create this yourself. You can format a number to have leading zeros using the D format where you specify the length you want. You can however use the date formats to get the last two digits of the year. So the following should give you the desired formatted string for a date.
public string ToYYJJJ(DateTime date)
{
return date.ToString("yy") + date.DayOfYear.ToString("D3");
}

Adding months to a DateTime variable

I have a datetime variable with value 12-02-2019 (12th Feb 2019) - this is what i want. But in my code, it is in MM-dd-yyyy format. It saves to db in MM-dd-yyyy format (2nd Dec 2019). When i return it from Datebase, it will be like 02-12-2019 (2nd Dec 2019).
int salesid = (int)dr["SalesID"]; // dr is the datarow
DateTime salesdate = (DateTime)dr["SalesDate"]; // 02-12-2019 (2nd Dec)
And I want to add 4 months to 12-02-2019 (12th Feb). But the runtime adds 4 months to 02-12-2019 (2nd dec) and i am getting 02-04-2020 !!!
DateTime servicedate = salesdate.AddMonths(4); // 2020-12-02
This is wrong. I want to specify the salesdate as 12th Feb 2019 and ii should get 12th June 2019 after adding 4 months to the salesdate.
How this is possible in c# ?
When you save to the DB, make sure you are specify a more verbose format that the DB cannot confuse. For example, if you supply write to the database with myDateTime.Format("dd MMM yyyy"); then it will not confuse the months and days around.
This will make sure that the format in your code, and in you database, all stay aligned.
The problem is in your INSERT statement. While you should be passing the DateTime as-is to your database API, instead of using strings, if you want a simple fix, instead of calling ToString() on your CurrentSaleItem.SaleDate, use a different overload that lets you specify the culture and/or format explicitly, like ToString(string, IFormatProvider)

DateTimePicker updown February missing

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.

GetMonthName: Valid values are between 1 and 13, inclusive. Why?

I accidentally passed 0 into DateTimeFormatInfo's GetMonthName method:
DateTimeFormatInfo info = new DateTimeFormatInfo();
var monthName = info.GetMonthName(0);
and got a System.ArgumentOutOfRangeException with this error message: Valid values are between 1 and 13, inclusive.
Passing in 1 through to 12 return "January" through to "December" but passing in 13 returns an empty string.
I can see why month numbers are not zero indexed, but what's month 13 for?
It's because calendar objects can accomodate 13 months (to handle calendars based on lunar months), see MSDN:
http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.getmonthname.aspx
Calendar objects can accommodate calendars with 13 months. For 12-month calendars, the empty string is always returned as the name of the 13th month.
According to MSDN
Calendar objects can accommodate
calendars with 13 months. For 12-month
calendars, the empty string is always
returned as the name of the 13th
month.
I guess it is used to determine the leap day in the julian calendar ( http://en.wikipedia.org/wiki/Julian_calendar ). As most of use use Gregorian calender just do not worry.

Categories

Resources