time compare? should be simple

B

Brian

Armin Zingler said:
There's a lot I would change. see inline



It's not very probable but as you retrieve the current date three times,
the date might change between the calls. I'd get the date only once. If
you want "today at 6:59:59 am", you can write

I want to be able to a default value, but let whoever uses this class access
to change the shift start and end times
ShiftStartTime = Date.Today.Add(New TimeSpan(6, 59, 59))


see above



If dtmTime contains a time only, use a TimeSpan object.

I wanted to use this incase the user changed the default shift end
Don't convert to String and back to Date. See solution above.



shorter:
a = dtmdate.date
I needed a way of making sure that the date and the time were the
same.....during testing I was using two datetimepickers and wanted to
make sure I had the correct date and time.
Why two conversions again? Declare dtmTime as Timespan and you can simply
write

Dim Ishift = dtmDate.Add(dtmTime)



I didn't check the logic because it's still not clear to me what you are
trying to achieve.
I am overloading a function for a shift schedule, I already have an
overload for function(dtm as date) and was asked to provide a function where
I the person coding would pass the date and time to check shiftschedule.
Some schedules go from 7am to 7pm and some go from 6am to 6pm. Part of the
problem i needed to find here is, if its a 7pm to 7am, I need to know if its
midnight to the end of the shift so I can roll back one day to get the team
that started the shift.
I will try to use your ideas and see how that works.. thanks. now you have
a better idea of what I am trying to do, any other ideas?
Thank you,
Brian
 
A

Armin Zingler

Brian said:
ok.. how do i convert the value of the datetimepicker to a timespan value?

You don't have to convert it. As I wrote in my first post:

YourDateTimePicker.Value.TimeOfDay

Be aware that it can also include fractions of a second that are not
displayed. To get rid of them:

Dim time = YourDateTimePicker.Value.TimeOfDay
time = New TimeSpan(time.Hours, time.Minutes, time.Seconds)



Armin
 
A

Armin Zingler

Brian said:
I want to be able to a default value, but let whoever uses this
class access to change the shift start and end times

What is the default value for what?
I wanted to use this incase the user changed the default shift end

I don't see the relation to why you convert it twice.

I needed a way of making sure that the date and the time were the
same.....during testing I was using two datetimepickers and wanted
to make sure I had the correct date and time.

Which time? Which date? Which date do you consider "correct"?

I am overloading a function for a shift schedule, I already have an
overload for function(dtm as date) and was asked to provide a
function where I the person coding would pass the date and time to
check shiftschedule. Some schedules go from 7am to 7pm and some go
from 6am to 6pm. Part of the problem i needed to find here is, if
its a 7pm to 7am,

What do you want to know? 7pm is greater than 7am, so just compare the two
times.
I need to know if its midnight to the end of the
shift

What means "its midnight to the end of the shift"? What is "it"?
so I can roll back one day to get the team that started the
shift.

What means "roll back"? Subtract 1 day? But you only have times, not days.
I will try to use your ideas and see how that works.. thanks. now
you have a better idea of what I am trying to do, any other ideas?
Thank you,
Brian


The definition of the task is still not clear. If was the programmer you
want to write the function, I wouldn't know what to do.


Armin
 
J

James Hahn

You can't. A datetimepicker returns a number representing a moment in time.
A timespan is a length of time. You need two points in time to calculate a
timespan. You can use two datetimepicker values to calculate a timespan (as
per examples already provided), or you can compare a datetimepicker datetime
to some arbitrary moment in time such as zero or midnight last night or now
and calculate the timespan. But you can't convert a single datepickertime
to a timespan.
 
B

Brian

Armin Zingler said:
What is the default value for what?
this would be the default value for starting shift time.. then shiftend
would be the shift end time.. this is 7am
Public ShiftStartTime As Date = New DateTime(Today.Year, Today.Month,
Today.Day, 6, 59, 59)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top