DateValue(Now)-7
Hi All
I'm passing today's date on DateTimePicker through Form load as shown below:
Question on DateTimePicker1.VAlue , I want to show the default date like DateValue(Now)-7 , seven days before today's date
Thanks for your help
Kind regards,
Farhan
I'm passing today's date on DateTimePicker through Form load as shown below:
Question on DateTimePicker1.VAlue , I want to show the default date like DateValue(Now)-7 , seven days before today's date
Private Sub Form1_Load(ByVal sender As object, ByVal e As EventArgs)
    DateTimePicker1.Value = DateValue(Now)
      DateTimePicker2.Value = DateValue(Now)
     Â
    End Sub
Thanks for your help
Kind regards,
Farhan
Comments
Thanks Its working but during run its generate following error;
Unhandles exception has occured in a component in your application
If you click Continue, the application will ignore this error and attempt to continue
Conversion from sting "24/09/2017 23:11:05 00:00" to type Date is not valid
at the bottom of my code I'm using following codes passing the DAtePicker value into variable and concatenate with 00:00
Thanks for your help
a. start date (reset time value to zero, just get the date portion)
DateTime.Now returns 24/09/2017 23:11:05:001
DateTime.Now.Date returns 24/09/2017 00:00:00:000
b. end date (time = 23:59:59:999)
DateTime.Now.Date.AddDays(1).AddMilliseconds(-1);
c. convert to string
DateTime.Now.Date.AddDays(1).AddMilliseconds(-1).ToString("dd /MM/yyyy HH:mm:ss");
d. beware passing datetime value to ms access database
ms access doesnt recoqnize milliseconds, therefore, you must use string in this context in order to remove milliseconds
ToString("dd /MM/yyyy HH:mm:ss");
e. parameter in fastreport by default is string, but you may change the datatype to int or datetime, etc