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

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).

Related

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.

DateTimePicker Default Value

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.

vb Count Up From Time (Last Updated: ** Seconds/Minutes Ago)

Okay, I hate just posting a question with no code, but I literally have no idea how to get started other than to user a Timer. I have a Visual Basics program which works with an SQL Table. I'd like to have a label which shows the user how 'old' their display of the table is.
Each time they edit or refresh the table a label is refreshed with a current time stamp. Formatted as 03:19;27.
However, I'd like to show how many seconds or even just minutes the table was last updated.
For example: 'Last updated: 22 Seconds Ago' OR 'Last Updated: Less Than A Minute Ago'.
How could I do this?
The TimeSpan object provides all of the properties you need to format the message however you want. The formatting options in it's ToString method may also be very helpful to you. To get a TimeSpan object, you can simply subtract one Date from another, like this:
Dim span As TimeSpan = lastQueryDate - Date.Now
Dim message As String = String.Format("Last Updated: {0} Seconds Ago", span.TotalSeconds)
Or, if you want to use a Stopwatch object, you could get the span of time since the stopwatch was started by accessing its Elapsed property, which is also a TimeSpan object.

Restricting Date Value of Parameter in SSRS

I have two parameters: Start Date and End Date, that filter records to include only those in this range.
Issue one: End date cannot be earlier than Start Date - I have a solution currently that just hides the data objects and displays a text box telling the user to re-enter a valid date range. Maybe there's a better solution
(Bigger) Issue two: I need to restrict users selecting Start date to only dates after a certain date eg. 5/25/2013. I tried a function in custom code to check and change, but unfortunately Parameters in custom code are read-only. I thought of a check in custom code and refreshing the parameter to default (an appropriate value eg. 5/25/2013) but I haven't been able to do that.
Something like this would be ideal:
Public Function DateCheck()
If (Report.Parameters!Open.Value < DateValue("5/25/2013"))
Report.Parameters!Open.Value = DateValue("5/25/2013") 'or refresh to default value
End If
End Function
Also, where do I put the Code.DateCheck() call if it works?
Looking forward to positive responses
I create a second but hidden parameter tor both that will modify them as required e.g. a second open called open_mod that is automatically set by a dummy sql like (example is in Oracle):
Select greatest(#open, '25/MAY/2013') from dual

VB time input, a better way to do it?

Working on a handy program for my boss at work as a summer project in between semesters both to make life easier for her, and to practice and improve my skills. Intent is to allow her to quickly and easily calculate the hours and minutes the person worked. The form itself has a series of text boxes for the Clock in and Clock out time for each day that week. Currently it attempts to convert the txtbox text into a Date variable, then .Subtract()'s the start from the end and stores it in a rolling total variable which is displayed at the bottom of the form. I can't help but think there is a better way of going about doing this, and I'm absolutely certain that having the below block of code 21 times (7 days, 3 shifts) is inefficient.
Dim StartTime As Date
Dim EndTime As Date
Dim Worked As System.TimeSpan
Dim WorkedTotal As System.TimeSpan
If chkFirst.Checked = True Then
StartTime = CDate(txtMonStart.Text)
EndTime = CDate(txtMonEnd.Text)
EndTime = EndTime.AddHours(12)
Worked = EndTime.Subtract(StartTime)
lblMonWork.Text = Worked.ToString()
WorkedTotal += Worked
Currently it works, mostly. The user has to enter the ":" in the time input, and if the total exceeds 24 hours, it displays a day column (40 hour 12 min work week displays as 1.16:12). I'd like to eliminate both of these unplanned features and allow for my input validation to take place when the focus changes to another box. A changing bgcolor would indicate an invalid input.
Any bright ideas?
Instead of using TextBox for the time input, use DateTimePicker, just change the Format property to Time.
Handle the Validating event of the DateTimePicker and if it's invalid just set e.Cancel = False, that way they can't save changes unless it's valid. Or if you want them to be able to leave the DateTimePicker and just change the colour, just handle the ValueChanged event instead.
Regarding your code sample, I haven't really looked at the logic of it, but instead of having the same code 21 times, just move the code into a separate function and then call that function with the start and end times as parameters and it can return the workedtime as it's return value.
I'm not sure what your UI looks like but if you're repeating the start time and end time input control multiple times as well it might be worth looking at creating your own usercontrol that can contain one each of the start and end time controls, and then you could have the validation be inside that user control so you don't have to have lots of event handlers etc.