none
Year, Month, and Day parameters decsribe an un-resentable DateTime (System.ArgumentOutOfRangeExecption: RRS feed

  • Question

  • Hallo

    We got a strange error this morning, we are already on a version 2 build on the project which is working on numerous computers.

    Last night all was still working and compiling without any issues, this morning we get the error message from one of the Date time pickers that the user will select the Year and month only, when taking the default back to long or short date all works. But when using the custom format we get the Exception. Can somebody please let us know what could cause this?

          private void SetDataGridFormat()
            {
                dtpFilter.Value = DateTime.Now;   //This is the one with the exception error
                dtpFilter.Format = DateTimePickerFormat.Custom;
                dtpFilter.CustomFormat = "yyyy MMMM";
                dtpFilter.ShowUpDown = true;
    
                dtpClockIn.Format = DateTimePickerFormat.Custom;
                dtpClockIn.CustomFormat = "HH:mm:ss";
    
                dtpClockOut.Format = DateTimePickerFormat.Custom;
                dtpClockOut.CustomFormat = "HH:mm:ss";
    
            }


    labjac

    Wednesday, October 31, 2018 5:02 AM

Answers

  • Hello,

    Hope this helps

            private void SetDataGridFormat()
            {
                try
                {
                    dtpFilter.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);   
                    dtpFilter.Format = DateTimePickerFormat.Custom;
                    dtpFilter.CustomFormat = "yyyy MMMM";
                    dtpFilter.ShowUpDown = true;
                    dtpClockIn.Format = DateTimePickerFormat.Custom;
                    dtpClockIn.CustomFormat = "HH:mm:ss";
                    dtpClockOut.Format = DateTimePickerFormat.Custom;
                    dtpClockOut.CustomFormat = "HH:mm:ss";
                }
                catch (Exception ex) { string errormsg = ex.ToString(); }
            }

    • Marked as answer by labjac Wednesday, October 31, 2018 9:13 AM
    Wednesday, October 31, 2018 7:26 AM

All replies

  • Try this:

       var n = DateTime.Now.Date;

       dtpFilter.Value = new DateTime( n.Year, n.Month, 1 );


    Wednesday, October 31, 2018 6:50 AM
  • Hello,

    Hope this helps

            private void SetDataGridFormat()
            {
                try
                {
                    dtpFilter.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);   
                    dtpFilter.Format = DateTimePickerFormat.Custom;
                    dtpFilter.CustomFormat = "yyyy MMMM";
                    dtpFilter.ShowUpDown = true;
                    dtpClockIn.Format = DateTimePickerFormat.Custom;
                    dtpClockIn.CustomFormat = "HH:mm:ss";
                    dtpClockOut.Format = DateTimePickerFormat.Custom;
                    dtpClockOut.CustomFormat = "HH:mm:ss";
                }
                catch (Exception ex) { string errormsg = ex.ToString(); }
            }

    • Marked as answer by labjac Wednesday, October 31, 2018 9:13 AM
    Wednesday, October 31, 2018 7:26 AM
  • Thank you.

    Still a misery why it worked for this time till this morning, but your solution worked.

    Thanks all..


    labjac

    Wednesday, October 31, 2018 9:14 AM