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










share|improve this question






















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






  • 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















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










share|improve this question






















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






  • 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













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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 11:15









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






  • 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


















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






  • 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
















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












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 set Option Strict On, possibly Option 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.







share|improve this answer























    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',
    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
    });


    }
    });














    draft saved

    draft discarded


















    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








    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 set Option Strict On, possibly Option 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.







    share|improve this answer



























      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 set Option Strict On, possibly Option 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.







      share|improve this answer

























        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 set Option Strict On, possibly Option 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.







        share|improve this answer














        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 set Option Strict On, possibly Option 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.








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 19 at 17:38

























        answered Nov 19 at 12:36









        Jimi

        6,08421233




        6,08421233






























            draft saved

            draft discarded




















































            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


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




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy