Subtracting minutes from a timestamp in msexcel












0















I am extracting a timestamp from a cell in the format like Tue Nov 06 07:33:00 UTC 2018. Now, using vbscript code or vba code I want to subtract some minutes from the above mentioned timestamp. How can I achieve that?










share|improve this question























  • What have you tried so far?

    – Nathan_Sav
    Nov 13 '18 at 11:15











  • In Excel, timestamps are written in seconds, so if you want to subtract a number of minutes, multiply this number by 60 and subtract it.

    – Dominique
    Nov 13 '18 at 13:43
















0















I am extracting a timestamp from a cell in the format like Tue Nov 06 07:33:00 UTC 2018. Now, using vbscript code or vba code I want to subtract some minutes from the above mentioned timestamp. How can I achieve that?










share|improve this question























  • What have you tried so far?

    – Nathan_Sav
    Nov 13 '18 at 11:15











  • In Excel, timestamps are written in seconds, so if you want to subtract a number of minutes, multiply this number by 60 and subtract it.

    – Dominique
    Nov 13 '18 at 13:43














0












0








0








I am extracting a timestamp from a cell in the format like Tue Nov 06 07:33:00 UTC 2018. Now, using vbscript code or vba code I want to subtract some minutes from the above mentioned timestamp. How can I achieve that?










share|improve this question














I am extracting a timestamp from a cell in the format like Tue Nov 06 07:33:00 UTC 2018. Now, using vbscript code or vba code I want to subtract some minutes from the above mentioned timestamp. How can I achieve that?







excel vba vbscript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 11:05









Ankur PatelAnkur Patel

813




813













  • What have you tried so far?

    – Nathan_Sav
    Nov 13 '18 at 11:15











  • In Excel, timestamps are written in seconds, so if you want to subtract a number of minutes, multiply this number by 60 and subtract it.

    – Dominique
    Nov 13 '18 at 13:43



















  • What have you tried so far?

    – Nathan_Sav
    Nov 13 '18 at 11:15











  • In Excel, timestamps are written in seconds, so if you want to subtract a number of minutes, multiply this number by 60 and subtract it.

    – Dominique
    Nov 13 '18 at 13:43

















What have you tried so far?

– Nathan_Sav
Nov 13 '18 at 11:15





What have you tried so far?

– Nathan_Sav
Nov 13 '18 at 11:15













In Excel, timestamps are written in seconds, so if you want to subtract a number of minutes, multiply this number by 60 and subtract it.

– Dominique
Nov 13 '18 at 13:43





In Excel, timestamps are written in seconds, so if you want to subtract a number of minutes, multiply this number by 60 and subtract it.

– Dominique
Nov 13 '18 at 13:43












2 Answers
2






active

oldest

votes


















0














split(split("Tue Nov 06 07:33:00 UTC 2018",":")(1),":")(0)


Will give you the minutes on their own. You can assign the splits to arrays, then rejoin with the correct minutes using `join



Something like so



Public Function addToTimeStamp(strTimeStamp As String, lngMinutes As Long) As String

Dim a() As String

a = Split(strTimeStamp, " ")
a(3) = DateAdd("n", lngMinutes, a(3))

addToTimeStamp = Join(a, " ")

End Function





share|improve this answer


























  • Thanks Nathan. It worked like a charm for me. :)

    – Ankur Patel
    Nov 23 '18 at 16:05



















0














Without going into VBA, you could separate the time stamp from the date, then work on the time stamp and adjust the date accordingly.



Assuming your dates are in the column A and that the timestamp always take the same structure, starting from row number 2



So first you create a column where there is only the time stamp, that is column B:



=MID(A2,FIND("UTC",A2)-9,8)



07:33:00




This first finds the position of "UTC" within the string then extract 8 characters starting from 9 characters to the left (accounting for the space between the time and "UTC").



Already there you can work on the minutes/hours/seconds.



Hours:



=NUMBERVALUE(LEFT(B2,2))



07




Minutes:



=NUMBERVALUE(Mid(B2,4,2))



33




Seconds:



=NUMBERVALUE(Right(B2,2))



00




You can also extract the date part of the time stamp using the same logic. Column C:



=MID(A2,FIND(B2,A2)-11,10)



Tue Nov 06




Finally you can also combine all of that into an Excel date and do your operations directly on the resulting number (This will ensure that you get a new valid date which account for incrementing/decrementing hours/days/months/years, it will also automatically account for leap years.)



Final date, including the time stamp, Column D:



=DATEVALUE(MID(A2,FIND(B2,A2)-3,2)&"-"&MID(A2,FIND(B2,A2)-7,3)&"-"&RIGHT(A2,4))+NUMBERVALUE(LEFT(B2,2))/24+NUMBERVALUE(MID(B2,4,2))/(24*60)+NUMBERVALUE(RIGHT(B2,2))/(24*60*60)



43410.3145833333




On this final number you can simply increase/decrease the number of minutes by adding it directly to it. The unit of this number is "days" so one minute is equal to 1/(24*60) and one hour is 1/24. Example of removing 33 minutes:



=D2 - 33/(24*60)



43410.2916666667




Changing the formatting to [dd/mm/yyyy hh:mm] will then result in:




06/11/2018 07:00:00







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


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279642%2fsubtracting-minutes-from-a-timestamp-in-msexcel%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    split(split("Tue Nov 06 07:33:00 UTC 2018",":")(1),":")(0)


    Will give you the minutes on their own. You can assign the splits to arrays, then rejoin with the correct minutes using `join



    Something like so



    Public Function addToTimeStamp(strTimeStamp As String, lngMinutes As Long) As String

    Dim a() As String

    a = Split(strTimeStamp, " ")
    a(3) = DateAdd("n", lngMinutes, a(3))

    addToTimeStamp = Join(a, " ")

    End Function





    share|improve this answer


























    • Thanks Nathan. It worked like a charm for me. :)

      – Ankur Patel
      Nov 23 '18 at 16:05
















    0














    split(split("Tue Nov 06 07:33:00 UTC 2018",":")(1),":")(0)


    Will give you the minutes on their own. You can assign the splits to arrays, then rejoin with the correct minutes using `join



    Something like so



    Public Function addToTimeStamp(strTimeStamp As String, lngMinutes As Long) As String

    Dim a() As String

    a = Split(strTimeStamp, " ")
    a(3) = DateAdd("n", lngMinutes, a(3))

    addToTimeStamp = Join(a, " ")

    End Function





    share|improve this answer


























    • Thanks Nathan. It worked like a charm for me. :)

      – Ankur Patel
      Nov 23 '18 at 16:05














    0












    0








    0







    split(split("Tue Nov 06 07:33:00 UTC 2018",":")(1),":")(0)


    Will give you the minutes on their own. You can assign the splits to arrays, then rejoin with the correct minutes using `join



    Something like so



    Public Function addToTimeStamp(strTimeStamp As String, lngMinutes As Long) As String

    Dim a() As String

    a = Split(strTimeStamp, " ")
    a(3) = DateAdd("n", lngMinutes, a(3))

    addToTimeStamp = Join(a, " ")

    End Function





    share|improve this answer















    split(split("Tue Nov 06 07:33:00 UTC 2018",":")(1),":")(0)


    Will give you the minutes on their own. You can assign the splits to arrays, then rejoin with the correct minutes using `join



    Something like so



    Public Function addToTimeStamp(strTimeStamp As String, lngMinutes As Long) As String

    Dim a() As String

    a = Split(strTimeStamp, " ")
    a(3) = DateAdd("n", lngMinutes, a(3))

    addToTimeStamp = Join(a, " ")

    End Function






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 13 '18 at 11:22

























    answered Nov 13 '18 at 11:16









    Nathan_SavNathan_Sav

    5,7191618




    5,7191618













    • Thanks Nathan. It worked like a charm for me. :)

      – Ankur Patel
      Nov 23 '18 at 16:05



















    • Thanks Nathan. It worked like a charm for me. :)

      – Ankur Patel
      Nov 23 '18 at 16:05

















    Thanks Nathan. It worked like a charm for me. :)

    – Ankur Patel
    Nov 23 '18 at 16:05





    Thanks Nathan. It worked like a charm for me. :)

    – Ankur Patel
    Nov 23 '18 at 16:05













    0














    Without going into VBA, you could separate the time stamp from the date, then work on the time stamp and adjust the date accordingly.



    Assuming your dates are in the column A and that the timestamp always take the same structure, starting from row number 2



    So first you create a column where there is only the time stamp, that is column B:



    =MID(A2,FIND("UTC",A2)-9,8)



    07:33:00




    This first finds the position of "UTC" within the string then extract 8 characters starting from 9 characters to the left (accounting for the space between the time and "UTC").



    Already there you can work on the minutes/hours/seconds.



    Hours:



    =NUMBERVALUE(LEFT(B2,2))



    07




    Minutes:



    =NUMBERVALUE(Mid(B2,4,2))



    33




    Seconds:



    =NUMBERVALUE(Right(B2,2))



    00




    You can also extract the date part of the time stamp using the same logic. Column C:



    =MID(A2,FIND(B2,A2)-11,10)



    Tue Nov 06




    Finally you can also combine all of that into an Excel date and do your operations directly on the resulting number (This will ensure that you get a new valid date which account for incrementing/decrementing hours/days/months/years, it will also automatically account for leap years.)



    Final date, including the time stamp, Column D:



    =DATEVALUE(MID(A2,FIND(B2,A2)-3,2)&"-"&MID(A2,FIND(B2,A2)-7,3)&"-"&RIGHT(A2,4))+NUMBERVALUE(LEFT(B2,2))/24+NUMBERVALUE(MID(B2,4,2))/(24*60)+NUMBERVALUE(RIGHT(B2,2))/(24*60*60)



    43410.3145833333




    On this final number you can simply increase/decrease the number of minutes by adding it directly to it. The unit of this number is "days" so one minute is equal to 1/(24*60) and one hour is 1/24. Example of removing 33 minutes:



    =D2 - 33/(24*60)



    43410.2916666667




    Changing the formatting to [dd/mm/yyyy hh:mm] will then result in:




    06/11/2018 07:00:00







    share|improve this answer




























      0














      Without going into VBA, you could separate the time stamp from the date, then work on the time stamp and adjust the date accordingly.



      Assuming your dates are in the column A and that the timestamp always take the same structure, starting from row number 2



      So first you create a column where there is only the time stamp, that is column B:



      =MID(A2,FIND("UTC",A2)-9,8)



      07:33:00




      This first finds the position of "UTC" within the string then extract 8 characters starting from 9 characters to the left (accounting for the space between the time and "UTC").



      Already there you can work on the minutes/hours/seconds.



      Hours:



      =NUMBERVALUE(LEFT(B2,2))



      07




      Minutes:



      =NUMBERVALUE(Mid(B2,4,2))



      33




      Seconds:



      =NUMBERVALUE(Right(B2,2))



      00




      You can also extract the date part of the time stamp using the same logic. Column C:



      =MID(A2,FIND(B2,A2)-11,10)



      Tue Nov 06




      Finally you can also combine all of that into an Excel date and do your operations directly on the resulting number (This will ensure that you get a new valid date which account for incrementing/decrementing hours/days/months/years, it will also automatically account for leap years.)



      Final date, including the time stamp, Column D:



      =DATEVALUE(MID(A2,FIND(B2,A2)-3,2)&"-"&MID(A2,FIND(B2,A2)-7,3)&"-"&RIGHT(A2,4))+NUMBERVALUE(LEFT(B2,2))/24+NUMBERVALUE(MID(B2,4,2))/(24*60)+NUMBERVALUE(RIGHT(B2,2))/(24*60*60)



      43410.3145833333




      On this final number you can simply increase/decrease the number of minutes by adding it directly to it. The unit of this number is "days" so one minute is equal to 1/(24*60) and one hour is 1/24. Example of removing 33 minutes:



      =D2 - 33/(24*60)



      43410.2916666667




      Changing the formatting to [dd/mm/yyyy hh:mm] will then result in:




      06/11/2018 07:00:00







      share|improve this answer


























        0












        0








        0







        Without going into VBA, you could separate the time stamp from the date, then work on the time stamp and adjust the date accordingly.



        Assuming your dates are in the column A and that the timestamp always take the same structure, starting from row number 2



        So first you create a column where there is only the time stamp, that is column B:



        =MID(A2,FIND("UTC",A2)-9,8)



        07:33:00




        This first finds the position of "UTC" within the string then extract 8 characters starting from 9 characters to the left (accounting for the space between the time and "UTC").



        Already there you can work on the minutes/hours/seconds.



        Hours:



        =NUMBERVALUE(LEFT(B2,2))



        07




        Minutes:



        =NUMBERVALUE(Mid(B2,4,2))



        33




        Seconds:



        =NUMBERVALUE(Right(B2,2))



        00




        You can also extract the date part of the time stamp using the same logic. Column C:



        =MID(A2,FIND(B2,A2)-11,10)



        Tue Nov 06




        Finally you can also combine all of that into an Excel date and do your operations directly on the resulting number (This will ensure that you get a new valid date which account for incrementing/decrementing hours/days/months/years, it will also automatically account for leap years.)



        Final date, including the time stamp, Column D:



        =DATEVALUE(MID(A2,FIND(B2,A2)-3,2)&"-"&MID(A2,FIND(B2,A2)-7,3)&"-"&RIGHT(A2,4))+NUMBERVALUE(LEFT(B2,2))/24+NUMBERVALUE(MID(B2,4,2))/(24*60)+NUMBERVALUE(RIGHT(B2,2))/(24*60*60)



        43410.3145833333




        On this final number you can simply increase/decrease the number of minutes by adding it directly to it. The unit of this number is "days" so one minute is equal to 1/(24*60) and one hour is 1/24. Example of removing 33 minutes:



        =D2 - 33/(24*60)



        43410.2916666667




        Changing the formatting to [dd/mm/yyyy hh:mm] will then result in:




        06/11/2018 07:00:00







        share|improve this answer













        Without going into VBA, you could separate the time stamp from the date, then work on the time stamp and adjust the date accordingly.



        Assuming your dates are in the column A and that the timestamp always take the same structure, starting from row number 2



        So first you create a column where there is only the time stamp, that is column B:



        =MID(A2,FIND("UTC",A2)-9,8)



        07:33:00




        This first finds the position of "UTC" within the string then extract 8 characters starting from 9 characters to the left (accounting for the space between the time and "UTC").



        Already there you can work on the minutes/hours/seconds.



        Hours:



        =NUMBERVALUE(LEFT(B2,2))



        07




        Minutes:



        =NUMBERVALUE(Mid(B2,4,2))



        33




        Seconds:



        =NUMBERVALUE(Right(B2,2))



        00




        You can also extract the date part of the time stamp using the same logic. Column C:



        =MID(A2,FIND(B2,A2)-11,10)



        Tue Nov 06




        Finally you can also combine all of that into an Excel date and do your operations directly on the resulting number (This will ensure that you get a new valid date which account for incrementing/decrementing hours/days/months/years, it will also automatically account for leap years.)



        Final date, including the time stamp, Column D:



        =DATEVALUE(MID(A2,FIND(B2,A2)-3,2)&"-"&MID(A2,FIND(B2,A2)-7,3)&"-"&RIGHT(A2,4))+NUMBERVALUE(LEFT(B2,2))/24+NUMBERVALUE(MID(B2,4,2))/(24*60)+NUMBERVALUE(RIGHT(B2,2))/(24*60*60)



        43410.3145833333




        On this final number you can simply increase/decrease the number of minutes by adding it directly to it. The unit of this number is "days" so one minute is equal to 1/(24*60) and one hour is 1/24. Example of removing 33 minutes:



        =D2 - 33/(24*60)



        43410.2916666667




        Changing the formatting to [dd/mm/yyyy hh:mm] will then result in:




        06/11/2018 07:00:00








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 13:18









        GTPVGTPV

        1464




        1464






























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279642%2fsubtracting-minutes-from-a-timestamp-in-msexcel%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

            Full-time equivalent

            さくらももこ

            13 indicted, 8 arrested in Calif. drug cartel investigation