Worked out timespan but need to mins 00:20:00 (HH:mm:ss)
up vote
0
down vote
favorite
Using two buttons to start and stop each using a
start_time = Format(Date.Now, "HH:mm:ss")
or
stop_time = Format(Date.Now, "HH:mm:ss")
to store the time and when submitting it uses a timespan to calculate the difference which works like a treat
Dim duration As TimeSpan = stop_time - start_time
Say if i recorded 00:59:00 minutes, how would i minus 00:20:00?, im guessing it would be another timespan with duration minus 00:20:00 but not sure how to get the 00:20:00 in a format to use this.
Cheers,
Pete
vb.net
add a comment |
up vote
0
down vote
favorite
Using two buttons to start and stop each using a
start_time = Format(Date.Now, "HH:mm:ss")
or
stop_time = Format(Date.Now, "HH:mm:ss")
to store the time and when submitting it uses a timespan to calculate the difference which works like a treat
Dim duration As TimeSpan = stop_time - start_time
Say if i recorded 00:59:00 minutes, how would i minus 00:20:00?, im guessing it would be another timespan with duration minus 00:20:00 but not sure how to get the 00:20:00 in a format to use this.
Cheers,
Pete
vb.net
Subtraction of dates produces a timespan. Subtraction of timespans also produces a timespan. Are you asking how to manually construct a timespan for 20 minutes?
– GSerg
Nov 19 at 11:25
TryTimeSpan.FromMinutes(20.0)
.
– Enigmativity
Nov 19 at 11:30
1
Why are you using strings? Use allTimeSpan
types:Dim start_time As TimeSpan = Date.Now.TimeOfDay
. ATimeSpan
of 20 minutes isDim SubSpan As TimeSpan = New TimeSpan(0, 20, 0)
. Then subtract:Dim duration As TimeSpan = stop_time - start_time
->duration = duration - SubSpan
– Jimi
Nov 19 at 11:31
@Jimi - Why not post that as an answer?
– Enigmativity
Nov 19 at 11:32
1
You should try settingOption Strict On
and see what that does to your code. (If you can get past the initial shock it'll make you a better coder.)
– Enigmativity
Nov 19 at 11:39
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Using two buttons to start and stop each using a
start_time = Format(Date.Now, "HH:mm:ss")
or
stop_time = Format(Date.Now, "HH:mm:ss")
to store the time and when submitting it uses a timespan to calculate the difference which works like a treat
Dim duration As TimeSpan = stop_time - start_time
Say if i recorded 00:59:00 minutes, how would i minus 00:20:00?, im guessing it would be another timespan with duration minus 00:20:00 but not sure how to get the 00:20:00 in a format to use this.
Cheers,
Pete
vb.net
Using two buttons to start and stop each using a
start_time = Format(Date.Now, "HH:mm:ss")
or
stop_time = Format(Date.Now, "HH:mm:ss")
to store the time and when submitting it uses a timespan to calculate the difference which works like a treat
Dim duration As TimeSpan = stop_time - start_time
Say if i recorded 00:59:00 minutes, how would i minus 00:20:00?, im guessing it would be another timespan with duration minus 00:20:00 but not sure how to get the 00:20:00 in a format to use this.
Cheers,
Pete
vb.net
vb.net
asked Nov 19 at 11:15
Peter James
366
366
Subtraction of dates produces a timespan. Subtraction of timespans also produces a timespan. Are you asking how to manually construct a timespan for 20 minutes?
– GSerg
Nov 19 at 11:25
TryTimeSpan.FromMinutes(20.0)
.
– Enigmativity
Nov 19 at 11:30
1
Why are you using strings? Use allTimeSpan
types:Dim start_time As TimeSpan = Date.Now.TimeOfDay
. ATimeSpan
of 20 minutes isDim SubSpan As TimeSpan = New TimeSpan(0, 20, 0)
. Then subtract:Dim duration As TimeSpan = stop_time - start_time
->duration = duration - SubSpan
– Jimi
Nov 19 at 11:31
@Jimi - Why not post that as an answer?
– Enigmativity
Nov 19 at 11:32
1
You should try settingOption Strict On
and see what that does to your code. (If you can get past the initial shock it'll make you a better coder.)
– Enigmativity
Nov 19 at 11:39
add a comment |
Subtraction of dates produces a timespan. Subtraction of timespans also produces a timespan. Are you asking how to manually construct a timespan for 20 minutes?
– GSerg
Nov 19 at 11:25
TryTimeSpan.FromMinutes(20.0)
.
– Enigmativity
Nov 19 at 11:30
1
Why are you using strings? Use allTimeSpan
types:Dim start_time As TimeSpan = Date.Now.TimeOfDay
. ATimeSpan
of 20 minutes isDim SubSpan As TimeSpan = New TimeSpan(0, 20, 0)
. Then subtract:Dim duration As TimeSpan = stop_time - start_time
->duration = duration - SubSpan
– Jimi
Nov 19 at 11:31
@Jimi - Why not post that as an answer?
– Enigmativity
Nov 19 at 11:32
1
You should try settingOption Strict On
and see what that does to your code. (If you can get past the initial shock it'll make you a better coder.)
– Enigmativity
Nov 19 at 11:39
Subtraction of dates produces a timespan. Subtraction of timespans also produces a timespan. Are you asking how to manually construct a timespan for 20 minutes?
– GSerg
Nov 19 at 11:25
Subtraction of dates produces a timespan. Subtraction of timespans also produces a timespan. Are you asking how to manually construct a timespan for 20 minutes?
– GSerg
Nov 19 at 11:25
Try
TimeSpan.FromMinutes(20.0)
.– Enigmativity
Nov 19 at 11:30
Try
TimeSpan.FromMinutes(20.0)
.– Enigmativity
Nov 19 at 11:30
1
1
Why are you using strings? Use all
TimeSpan
types: Dim start_time As TimeSpan = Date.Now.TimeOfDay
. A TimeSpan
of 20 minutes is Dim SubSpan As TimeSpan = New TimeSpan(0, 20, 0)
. Then subtract: Dim duration As TimeSpan = stop_time - start_time
-> duration = duration - SubSpan
– Jimi
Nov 19 at 11:31
Why are you using strings? Use all
TimeSpan
types: Dim start_time As TimeSpan = Date.Now.TimeOfDay
. A TimeSpan
of 20 minutes is Dim SubSpan As TimeSpan = New TimeSpan(0, 20, 0)
. Then subtract: Dim duration As TimeSpan = stop_time - start_time
-> duration = duration - SubSpan
– Jimi
Nov 19 at 11:31
@Jimi - Why not post that as an answer?
– Enigmativity
Nov 19 at 11:32
@Jimi - Why not post that as an answer?
– Enigmativity
Nov 19 at 11:32
1
1
You should try setting
Option Strict On
and see what that does to your code. (If you can get past the initial shock it'll make you a better coder.)– Enigmativity
Nov 19 at 11:39
You should try setting
Option Strict On
and see what that does to your code. (If you can get past the initial shock it'll make you a better coder.)– Enigmativity
Nov 19 at 11:39
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
As of now, you're using strings to store DateTime
values. There's no reason for it.
Strings should be used - when dealing with DateTime structure - for presentation only.
Use a TimeSpan to perform these calculations.
Store the start time of an operation:
Dim StartTime As TimeSpan = Date.Now.TimeOfDay
Store the end time of an operation:
Dim StopTime As TimeSpan = Date.Now.TimeOfDay
Calculate the Duration:
Dim Duration As TimeSpan = StopTime - StartTime
A TimeSpan
value can be created with:
[TimeSpan] = new TimeSpan([Hours], [Minutes], [Seconds])
or: [TimeSpan] = TimeSpan.FromSeconds([Seconds]) | TimeSpan.FromMinutes([Minutes]) | .FromHours([Hours])
etc.
Note that the first form accepts Integer
values, while the second form accepts Double
values: when inserting the value in minutes, add a #
to the value (indicating that the value is a Double
type) and see what happens.
Create a new TimeSpan
of 20
minutes and subtract it from the Duration
value:
Dim SubSpan As TimeSpan = New TimeSpan(0, 20, 0)
'Or
Dim SubSpan As TimeSpan = TimeSpan.FromMinutes(20.0#)
Duration -= SubSpan
Use the TimeSpan.ToString()
method to present the DateTime
/ TimeSpan
value in a human readable, localized, form:
TextBox1.Text = Duration.ToString()
Or using a specific format:
TextBox1.Text = duration.ToString("hh:mm:ss")
TextBox1.Text = duration.ToString("hh:mm:ss", CultureInfo.InvariantCulture)
TextBox1.Text = duration.ToString("hh:mm:ss", CultureInfo.CreateSpecificCulture("en-UK"))
As noted in the comments (and in many other questions every day), it would be
a great idea to setOption Strict On
, possiblyOption Explicit On
and (it can be really useful)Option Infer On
in the Project properties.
This will help a lot in making the right decision when declaring and using your Types.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
As of now, you're using strings to store DateTime
values. There's no reason for it.
Strings should be used - when dealing with DateTime structure - for presentation only.
Use a TimeSpan to perform these calculations.
Store the start time of an operation:
Dim StartTime As TimeSpan = Date.Now.TimeOfDay
Store the end time of an operation:
Dim StopTime As TimeSpan = Date.Now.TimeOfDay
Calculate the Duration:
Dim Duration As TimeSpan = StopTime - StartTime
A TimeSpan
value can be created with:
[TimeSpan] = new TimeSpan([Hours], [Minutes], [Seconds])
or: [TimeSpan] = TimeSpan.FromSeconds([Seconds]) | TimeSpan.FromMinutes([Minutes]) | .FromHours([Hours])
etc.
Note that the first form accepts Integer
values, while the second form accepts Double
values: when inserting the value in minutes, add a #
to the value (indicating that the value is a Double
type) and see what happens.
Create a new TimeSpan
of 20
minutes and subtract it from the Duration
value:
Dim SubSpan As TimeSpan = New TimeSpan(0, 20, 0)
'Or
Dim SubSpan As TimeSpan = TimeSpan.FromMinutes(20.0#)
Duration -= SubSpan
Use the TimeSpan.ToString()
method to present the DateTime
/ TimeSpan
value in a human readable, localized, form:
TextBox1.Text = Duration.ToString()
Or using a specific format:
TextBox1.Text = duration.ToString("hh:mm:ss")
TextBox1.Text = duration.ToString("hh:mm:ss", CultureInfo.InvariantCulture)
TextBox1.Text = duration.ToString("hh:mm:ss", CultureInfo.CreateSpecificCulture("en-UK"))
As noted in the comments (and in many other questions every day), it would be
a great idea to setOption Strict On
, possiblyOption Explicit On
and (it can be really useful)Option Infer On
in the Project properties.
This will help a lot in making the right decision when declaring and using your Types.
add a comment |
up vote
0
down vote
accepted
As of now, you're using strings to store DateTime
values. There's no reason for it.
Strings should be used - when dealing with DateTime structure - for presentation only.
Use a TimeSpan to perform these calculations.
Store the start time of an operation:
Dim StartTime As TimeSpan = Date.Now.TimeOfDay
Store the end time of an operation:
Dim StopTime As TimeSpan = Date.Now.TimeOfDay
Calculate the Duration:
Dim Duration As TimeSpan = StopTime - StartTime
A TimeSpan
value can be created with:
[TimeSpan] = new TimeSpan([Hours], [Minutes], [Seconds])
or: [TimeSpan] = TimeSpan.FromSeconds([Seconds]) | TimeSpan.FromMinutes([Minutes]) | .FromHours([Hours])
etc.
Note that the first form accepts Integer
values, while the second form accepts Double
values: when inserting the value in minutes, add a #
to the value (indicating that the value is a Double
type) and see what happens.
Create a new TimeSpan
of 20
minutes and subtract it from the Duration
value:
Dim SubSpan As TimeSpan = New TimeSpan(0, 20, 0)
'Or
Dim SubSpan As TimeSpan = TimeSpan.FromMinutes(20.0#)
Duration -= SubSpan
Use the TimeSpan.ToString()
method to present the DateTime
/ TimeSpan
value in a human readable, localized, form:
TextBox1.Text = Duration.ToString()
Or using a specific format:
TextBox1.Text = duration.ToString("hh:mm:ss")
TextBox1.Text = duration.ToString("hh:mm:ss", CultureInfo.InvariantCulture)
TextBox1.Text = duration.ToString("hh:mm:ss", CultureInfo.CreateSpecificCulture("en-UK"))
As noted in the comments (and in many other questions every day), it would be
a great idea to setOption Strict On
, possiblyOption Explicit On
and (it can be really useful)Option Infer On
in the Project properties.
This will help a lot in making the right decision when declaring and using your Types.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
As of now, you're using strings to store DateTime
values. There's no reason for it.
Strings should be used - when dealing with DateTime structure - for presentation only.
Use a TimeSpan to perform these calculations.
Store the start time of an operation:
Dim StartTime As TimeSpan = Date.Now.TimeOfDay
Store the end time of an operation:
Dim StopTime As TimeSpan = Date.Now.TimeOfDay
Calculate the Duration:
Dim Duration As TimeSpan = StopTime - StartTime
A TimeSpan
value can be created with:
[TimeSpan] = new TimeSpan([Hours], [Minutes], [Seconds])
or: [TimeSpan] = TimeSpan.FromSeconds([Seconds]) | TimeSpan.FromMinutes([Minutes]) | .FromHours([Hours])
etc.
Note that the first form accepts Integer
values, while the second form accepts Double
values: when inserting the value in minutes, add a #
to the value (indicating that the value is a Double
type) and see what happens.
Create a new TimeSpan
of 20
minutes and subtract it from the Duration
value:
Dim SubSpan As TimeSpan = New TimeSpan(0, 20, 0)
'Or
Dim SubSpan As TimeSpan = TimeSpan.FromMinutes(20.0#)
Duration -= SubSpan
Use the TimeSpan.ToString()
method to present the DateTime
/ TimeSpan
value in a human readable, localized, form:
TextBox1.Text = Duration.ToString()
Or using a specific format:
TextBox1.Text = duration.ToString("hh:mm:ss")
TextBox1.Text = duration.ToString("hh:mm:ss", CultureInfo.InvariantCulture)
TextBox1.Text = duration.ToString("hh:mm:ss", CultureInfo.CreateSpecificCulture("en-UK"))
As noted in the comments (and in many other questions every day), it would be
a great idea to setOption Strict On
, possiblyOption Explicit On
and (it can be really useful)Option Infer On
in the Project properties.
This will help a lot in making the right decision when declaring and using your Types.
As of now, you're using strings to store DateTime
values. There's no reason for it.
Strings should be used - when dealing with DateTime structure - for presentation only.
Use a TimeSpan to perform these calculations.
Store the start time of an operation:
Dim StartTime As TimeSpan = Date.Now.TimeOfDay
Store the end time of an operation:
Dim StopTime As TimeSpan = Date.Now.TimeOfDay
Calculate the Duration:
Dim Duration As TimeSpan = StopTime - StartTime
A TimeSpan
value can be created with:
[TimeSpan] = new TimeSpan([Hours], [Minutes], [Seconds])
or: [TimeSpan] = TimeSpan.FromSeconds([Seconds]) | TimeSpan.FromMinutes([Minutes]) | .FromHours([Hours])
etc.
Note that the first form accepts Integer
values, while the second form accepts Double
values: when inserting the value in minutes, add a #
to the value (indicating that the value is a Double
type) and see what happens.
Create a new TimeSpan
of 20
minutes and subtract it from the Duration
value:
Dim SubSpan As TimeSpan = New TimeSpan(0, 20, 0)
'Or
Dim SubSpan As TimeSpan = TimeSpan.FromMinutes(20.0#)
Duration -= SubSpan
Use the TimeSpan.ToString()
method to present the DateTime
/ TimeSpan
value in a human readable, localized, form:
TextBox1.Text = Duration.ToString()
Or using a specific format:
TextBox1.Text = duration.ToString("hh:mm:ss")
TextBox1.Text = duration.ToString("hh:mm:ss", CultureInfo.InvariantCulture)
TextBox1.Text = duration.ToString("hh:mm:ss", CultureInfo.CreateSpecificCulture("en-UK"))
As noted in the comments (and in many other questions every day), it would be
a great idea to setOption Strict On
, possiblyOption Explicit On
and (it can be really useful)Option Infer On
in the Project properties.
This will help a lot in making the right decision when declaring and using your Types.
edited Nov 19 at 17:38
answered Nov 19 at 12:36
Jimi
5,88321032
5,88321032
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373424%2fworked-out-timespan-but-need-to-mins-002000-hhmmss%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Subtraction of dates produces a timespan. Subtraction of timespans also produces a timespan. Are you asking how to manually construct a timespan for 20 minutes?
– GSerg
Nov 19 at 11:25
Try
TimeSpan.FromMinutes(20.0)
.– Enigmativity
Nov 19 at 11:30
1
Why are you using strings? Use all
TimeSpan
types:Dim start_time As TimeSpan = Date.Now.TimeOfDay
. ATimeSpan
of 20 minutes isDim SubSpan As TimeSpan = New TimeSpan(0, 20, 0)
. Then subtract:Dim duration As TimeSpan = stop_time - start_time
->duration = duration - SubSpan
– Jimi
Nov 19 at 11:31
@Jimi - Why not post that as an answer?
– Enigmativity
Nov 19 at 11:32
1
You should try setting
Option Strict On
and see what that does to your code. (If you can get past the initial shock it'll make you a better coder.)– Enigmativity
Nov 19 at 11:39