How to check if date is between two dates in python











up vote
1
down vote

favorite












How to check if a date is between two dates in python?



EDIT1: In excel, the date that I am reading is 7/13/2018 for example.










share|improve this question
























  • Give example of date format that you are using.
    – Nabin
    Jul 19 '17 at 4:15










  • Please see the update
    – Mat.S
    Jul 19 '17 at 4:16










  • Duplicate of How to tell if a date is between two other dates in Python?.
    – miradulo
    Jul 19 '17 at 4:20






  • 3




    Possible duplicate of How to tell if a date is between two other dates in Python?
    – Jacobm001
    Jul 19 '17 at 4:21















up vote
1
down vote

favorite












How to check if a date is between two dates in python?



EDIT1: In excel, the date that I am reading is 7/13/2018 for example.










share|improve this question
























  • Give example of date format that you are using.
    – Nabin
    Jul 19 '17 at 4:15










  • Please see the update
    – Mat.S
    Jul 19 '17 at 4:16










  • Duplicate of How to tell if a date is between two other dates in Python?.
    – miradulo
    Jul 19 '17 at 4:20






  • 3




    Possible duplicate of How to tell if a date is between two other dates in Python?
    – Jacobm001
    Jul 19 '17 at 4:21













up vote
1
down vote

favorite









up vote
1
down vote

favorite











How to check if a date is between two dates in python?



EDIT1: In excel, the date that I am reading is 7/13/2018 for example.










share|improve this question















How to check if a date is between two dates in python?



EDIT1: In excel, the date that I am reading is 7/13/2018 for example.







python






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 19 '17 at 4:16

























asked Jul 19 '17 at 4:14









Mat.S

6193824




6193824












  • Give example of date format that you are using.
    – Nabin
    Jul 19 '17 at 4:15










  • Please see the update
    – Mat.S
    Jul 19 '17 at 4:16










  • Duplicate of How to tell if a date is between two other dates in Python?.
    – miradulo
    Jul 19 '17 at 4:20






  • 3




    Possible duplicate of How to tell if a date is between two other dates in Python?
    – Jacobm001
    Jul 19 '17 at 4:21


















  • Give example of date format that you are using.
    – Nabin
    Jul 19 '17 at 4:15










  • Please see the update
    – Mat.S
    Jul 19 '17 at 4:16










  • Duplicate of How to tell if a date is between two other dates in Python?.
    – miradulo
    Jul 19 '17 at 4:20






  • 3




    Possible duplicate of How to tell if a date is between two other dates in Python?
    – Jacobm001
    Jul 19 '17 at 4:21
















Give example of date format that you are using.
– Nabin
Jul 19 '17 at 4:15




Give example of date format that you are using.
– Nabin
Jul 19 '17 at 4:15












Please see the update
– Mat.S
Jul 19 '17 at 4:16




Please see the update
– Mat.S
Jul 19 '17 at 4:16












Duplicate of How to tell if a date is between two other dates in Python?.
– miradulo
Jul 19 '17 at 4:20




Duplicate of How to tell if a date is between two other dates in Python?.
– miradulo
Jul 19 '17 at 4:20




3




3




Possible duplicate of How to tell if a date is between two other dates in Python?
– Jacobm001
Jul 19 '17 at 4:21




Possible duplicate of How to tell if a date is between two other dates in Python?
– Jacobm001
Jul 19 '17 at 4:21












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










You can convert the date so it can be easily compared in Python. Dates 1 and 2 are the converted dates, input_1 and input_2 are the two inputs from Excel. The second parameter passed in is the format in which the date is passed in.



date_1 = datetime.strptime(input_1, '%d/%m/%Y')
date_2 = datetime.strptime(input_2, '%d/%m/%Y')
date_3 = date(2017, 7, 19)


Now that you have the dates in the right format, I will check if date_3 falls within date_1 and date_2. This will return a Boolean.



date_1 < date_3 < date_2





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%2f45180858%2fhow-to-check-if-date-is-between-two-dates-in-python%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
    1
    down vote



    accepted










    You can convert the date so it can be easily compared in Python. Dates 1 and 2 are the converted dates, input_1 and input_2 are the two inputs from Excel. The second parameter passed in is the format in which the date is passed in.



    date_1 = datetime.strptime(input_1, '%d/%m/%Y')
    date_2 = datetime.strptime(input_2, '%d/%m/%Y')
    date_3 = date(2017, 7, 19)


    Now that you have the dates in the right format, I will check if date_3 falls within date_1 and date_2. This will return a Boolean.



    date_1 < date_3 < date_2





    share|improve this answer

























      up vote
      1
      down vote



      accepted










      You can convert the date so it can be easily compared in Python. Dates 1 and 2 are the converted dates, input_1 and input_2 are the two inputs from Excel. The second parameter passed in is the format in which the date is passed in.



      date_1 = datetime.strptime(input_1, '%d/%m/%Y')
      date_2 = datetime.strptime(input_2, '%d/%m/%Y')
      date_3 = date(2017, 7, 19)


      Now that you have the dates in the right format, I will check if date_3 falls within date_1 and date_2. This will return a Boolean.



      date_1 < date_3 < date_2





      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        You can convert the date so it can be easily compared in Python. Dates 1 and 2 are the converted dates, input_1 and input_2 are the two inputs from Excel. The second parameter passed in is the format in which the date is passed in.



        date_1 = datetime.strptime(input_1, '%d/%m/%Y')
        date_2 = datetime.strptime(input_2, '%d/%m/%Y')
        date_3 = date(2017, 7, 19)


        Now that you have the dates in the right format, I will check if date_3 falls within date_1 and date_2. This will return a Boolean.



        date_1 < date_3 < date_2





        share|improve this answer












        You can convert the date so it can be easily compared in Python. Dates 1 and 2 are the converted dates, input_1 and input_2 are the two inputs from Excel. The second parameter passed in is the format in which the date is passed in.



        date_1 = datetime.strptime(input_1, '%d/%m/%Y')
        date_2 = datetime.strptime(input_2, '%d/%m/%Y')
        date_3 = date(2017, 7, 19)


        Now that you have the dates in the right format, I will check if date_3 falls within date_1 and date_2. This will return a Boolean.



        date_1 < date_3 < date_2






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 19 '17 at 4:38









        PeskyPotato

        416415




        416415






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f45180858%2fhow-to-check-if-date-is-between-two-dates-in-python%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

            Futebolista

            Lallio

            Jornalista