DateTimePicker Default Value - vb.net

I am using VB.Net 2008.
I have two DateTimePicker. The first has a default value 8/24/2017 1:35 PM (as it was created Aug. 24. The second one has the default value of what is the current date and time. I haven't set their default values in Properties.
It is just weird for me that they have different default values. Anyway, my desired value is the current date and time.
I have also experienced confusion on my previous project regarding DateTimePicker where it has always default time 1:32 PM where time should be disregarded. The format is "Short" and the default value is the current date w/o time.
Can anyone explain why it happens?
Thank you in advance.

In my experience, a DateTimePicker contains the current date and time in its Value property unless you set it otherwise. Why that should not be happening for one of your controls, I don't know. In that case though, I'd suggest simply deleting that control and adding a new one. Hopefully that will behave as expected.
There's no such thing as a DateTimePicker that "disregards" time. The Value property of a DateTimePicker is type DateTime and a DateTime ALWAYS has both a date component and a time component. You can set the Format and optionally CustomFormat properties to show only the date, only the time or only some part thereof but that makes exactly zero difference to what's stored in the Value property.
Just like for any other DateTime value, if you want the Value of a DateTimePicker to represent just a date then you should zero the time. If you want to use the current date without a time then use DateTime.Today, where DateTime.Now would get you the current time as well as the current date. If you want to zero the time of any DateTime value, including the Value of a DateTimePicker, then you get its Date property. Note that that does not affect the original value, but creates a new DateTime value with the same date and the time zeroed, e.g.
Dim selectedDate = myDateTimePicker.Value.Date
Note that DateTime.Today simply returns DateTime.Now.Date.

Related

How to pass date value from gridview to datetimepicker

Currently I am working with Data Gridview and Datetime picker in VB.Net
And dont know how to pass the value from gridview to date time picker. please help
Below is Date Colume of gridview
This error occured after debug
I tried some code...
Student_Admission.DateTimePicker2.Value = CDate(DataGridView1.CurrentRow.Cells(1).Value)
in the first code you are converting to date then ToString. The value of DTP obviously cant hold that. To adjust the format you need to add a .Format property
The second code you supplied should work assuming there is a value that can be a date in cell(1) of the current row
Edit. ok, so you're not actually calling .ToString("mm/dd//yyyy") you are actually expecting the value to format as such? that's not going to work either.

How to add integer value from custom field to a custom date field in NetSuite?

I have been trying to figure out how to appropriately define a date within a newly created custom field that references the current transaction date and 'adds' an integer value from an existing custom field in NetSuite that's located on the same form (a PO). Each time I submit, I get an error for an invalid expression or the value is simple null.
Here's my code:
CASE WHEN {entity} = 'Test Vendor' THEN
{trandate} + {custbody01}
ELSE 56
END
"custbody01" represents an existing value that has been calculated within a custom field (integer). The idea is for a pre-calculated value (integer) to be added to the current transaction date to calculate a future date in the custom field. I am very new to NetSuite and could really use any help provided.
Thank You
I've had a similar requirement. I've needed to add an int to a date. I believe you just need to use the TO_DATE() function.
Here's the code I specifically used as a workflow condition, but I believe it would be transferable, so long as custbody01 is indeed an int value. (custbody456 is a custom date field, adding an integer value, to calculate another date field)
Estimated Ship Date=to_date({custbody456}) + 17
So I think for you, you may want to try:
TO_DATE({trandate}) + {custbody01})
When executing, this code will reference the existing custom field and add that value to the current transaction date.

Incorrect timestamp control value

After placing Timestamp control on my panel, I've changed it's properties to display only time, as I don't need date part.
Value shown on this control is, as expected, 00:00:00, but if I press up button I get 01:00:01, 01:00:02, ..., or if I press down button, I get 00:59:59, 00:59:58 and so on.
If I write 01:00:00 inside a text box of the control, it automatically switches back to 00:00:00.
If I change timestamp value to double, I get 0 for 00:00:00, -1 for 00:59:59, and 1 for 1:00:01.
So it seems as if this control uses 01:00:00 as a base time. Inside it's properties I've found minimum value of 01:00:00,000 1600-01-01. Changing it to 00:00:00 doesn't give expected result.
Is there any way for this control to work properly as a normal time span control ?
I don't know if the behavior is correct or not, but I can explain it.
The problem is that you're using absolute time. In absolute time, LV uses the first midnight of 1904 UTC as the epoch (the zero value) and when you have that value it displays it as all zeros. Once you change it, the display goes back to normal. The reason you're seeing 1:00:00 as the base is because you're in the GMT+1 timezone and LV automatically fixes the display when the value is not zero.
What I would suggest is replacing the timestamp control with a numeric control, going to the format page in the properties and changing the control to display relative time.
Alternatively, if you do want the time to be absolute, then set the value of the control to the correct timestamp using a local variable before starting.

Adding two different dates in VB.net, without using 'Now'

I have been looking through a bunch of different posts on here and on other sites for adding two dates together, but for some reason everyone wants to use 'Now'
I would like to know how to add two different dates together when neither of which are now!
I have tried a few things but I am getting casting errors. Also worth noting I am setting it to the value of a dateTime picker on my page.
MaxDate.Value = MinDate.Value + TimeSpan.FromDays(1)
'does not work
MaxDate.Value = Now + TimeSpan.FromDays(1)
'does work!
If it is not obvious, I have two date pickers on my page and when a radio button is clicked I want to set the 'End date' (maxdate.value) to whatever the 'Start date' (mindate.value) is, and add one day to it.
Thanks for the help!
Just do this:
MaxDate.Value = MidDate.Value.AddDays(1)
You don't need create a TimeSpan object for that because the Date type has built-in methods for doing incrementation by day, month, year, minute, etc.
The AddDays method does not alter the original date, it just returns a new Date object with the offset value.
By the way, if you want to subtract a day, there is no MinusDays method, just do x.AddDays(-1).

How to check if the user enters the default datetime?

I have two textboxes on the screen. They are used for startdate and enddate. If the user does not enter anything in the textboxes I pass nothing (VB.NET) to the webservice. When the webservice receive it on the other end it shows the value "#12:00:00 AM" which I think is the default for the datetime field. Anyway, now I do not want to pass this value to Stored procedure since it will not work. How can I check before sending values to sproc that the value is not the default datetime.
If you don't want to pass it to the WebService, why do you pass it anyway?
To see if a Date is not the "default-date":
If Not Date.MinValue = MyDate
I can think of two options here.
Since you already know that you're receiving "#12:00:00AM" when the field is not filled in, check if the value you receive is "#12:00:00AM".
Prior to passing the value to your stored procedure, create a new DateTime object. Compare the value you're receiving against the value in the new DateTime object.
Instead of DateTime use Nullable of DateTime. Then you can pass a null (or nothing) value to the web service and you use Date.HasValue to check if a value was entered/passed.