Worked out timespan but need to mins 00:20:00 (HH:mm:ss)
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 |
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 '18 at 11:25
TryTimeSpan.FromMinutes(20.0)
.
– Enigmativity
Nov 19 '18 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 '18 at 11:31
@Jimi - Why not post that as an answer?
– Enigmativity
Nov 19 '18 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 '18 at 11:39
add a comment |
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 '18 at 11:15
Peter JamesPeter James
437
437
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 '18 at 11:25
TryTimeSpan.FromMinutes(20.0)
.
– Enigmativity
Nov 19 '18 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 '18 at 11:31
@Jimi - Why not post that as an answer?
– Enigmativity
Nov 19 '18 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 '18 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 '18 at 11:25
TryTimeSpan.FromMinutes(20.0)
.
– Enigmativity
Nov 19 '18 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 '18 at 11:31
@Jimi - Why not post that as an answer?
– Enigmativity
Nov 19 '18 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 '18 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 '18 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 '18 at 11:25
Try
TimeSpan.FromMinutes(20.0)
.– Enigmativity
Nov 19 '18 at 11:30
Try
TimeSpan.FromMinutes(20.0)
.– Enigmativity
Nov 19 '18 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 '18 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 '18 at 11:31
@Jimi - Why not post that as an answer?
– Enigmativity
Nov 19 '18 at 11:32
@Jimi - Why not post that as an answer?
– Enigmativity
Nov 19 '18 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 '18 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 '18 at 11:39
add a comment |
1 Answer
1
active
oldest
votes
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 |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 |
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 |
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 '18 at 17:38
answered Nov 19 '18 at 12:36
JimiJimi
8,12241934
8,12241934
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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 '18 at 11:25
Try
TimeSpan.FromMinutes(20.0)
.– Enigmativity
Nov 19 '18 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 '18 at 11:31
@Jimi - Why not post that as an answer?
– Enigmativity
Nov 19 '18 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 '18 at 11:39